Monday, 8 May 2017

Getting the response for res.write() in nodejs using angularjs

I have the following router implemented which sends the data every one second.

router.get('/api/test-router', function(req,res){
    var currentTime = new Date();
    res.writeHead(200, {'Content-Type': 'text/html'});
    setInterval(function(){
        res.write(
            currentTime.getHours() + ':' + currentTime.getMinutes() + ':' + currentTime.getSeconds() + "\n"
        );

        setTimeout(function() {
            res.end();
        }, 10000);

    },1000);
})

I want to get the response of the above router on my client side using the angularjs $http.get method.

$http.get('/api/test-router').then(function(response){
    console.log(response.data)
});

The above angularjs code do not print anything in the console window.

Please help me to sort this problem out.



via Krisalay

No comments:

Post a Comment