0

I'm a newbie in node js and trying to build a simple app to build web pages from RSS feeds.

http.get('http://www.someurl.com/news?output=rss', function(res) {
    res.on('data', function(chunk) {
        resLength += chunk.length; 
        chunks.push(chunk);
    });
    res.on('end', function(chunk) {
        // combine all chunks and process feed XML.
    });
})

Processing the server response may go longer and will block the main thread.

How can I create an async operation to process the intermediate server response and send the result back?

0

2 Answers 2

1

In nodejs, you should not do stuff that uses extensive CPU time as it is single threaded server(event loop). Rest other stuff don't blocks the entire process. Server makes that request and continue doing other things, when the request comes back(after millions of clock cycles), you can execute the callback, all you need is the pointer to the callback.

therfore, You coudn't process asynchronously requests that has extensive CPU Usage. Apart from that, all other request works as if process asynchornously.

Sign up to request clarification or add additional context in comments.

2 Comments

He could make use of the child-process- Package to move that CPU-extensive tasks to another process. Then the server itself wouldnt be blocked...
Yeah thats cool, but theory of nodeJS says, its actually not suited for CPU extensive tasks. Although we can do stuff as you said..
0

have a look at expressjs.com, which is the entire world's go-to for node.js web apps, and the request package for getting http resources

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.