Search code examples
node.jssocketsexpressasynchronouskraken.js

Do I need a socket module for sending data to view after the res.render


this is my first post on Stack overflow.

I work on a little app with the framework kraken JS and I want to display a lot of data on a page from multiple API and sources.

Here is the concerned part of my controller :

    module.exports = function (router) {

        var model = new MainModel();

        router.get('/', function (req, res) {

            res.render('index', model)        

            getLastTweet('shug0', function(result) {        
                res.json(result);        
            });

        });        

    };

Now I would like to send the data I get from Twitter to my view without reloading the page. The purpose is to do this for multiples API with asyncronous response for every part of the page.

Do I need a socket module or Express can do this for me ?

(Sorry for approximative english)

Thomas


Solution

  • You'll probably want to look into WebSockets/Server-sent Events/Socket.IO for updating data in the background, such as tweets. In fact, currently the front page of http://socket.io shows just such an example that tracks tweets tagged with #socket.io or #javascript.