Skip to content Skip to sidebar Skip to footer

Console.log Printing Statements In The Wrong Order For Learnyounode Node.js Tutorial

I'm making a GET request, storing the data, and then noting the response is over. I have one console.log statement for when I'm done receiving the data and another for when the pr

Solution 1:

For all of the fuss about its asynchronous expressivity, node.js is single threaded and will only have one thread of execution per process - that means only one line of code will be executed at a time.

When you make the asynchronous call to http.get, node.js sends off an HTTP GET and defers execution of the callback until (1) the callback is ready to be called and (2) it runs out of synchronous (blocking) code to run. This explains why you always see "Program is finished" first - node.js has finished executing its blocking code and is ready to move on to handling the asynchronous callback that contains "Finished receiving data".

Post a Comment for "Console.log Printing Statements In The Wrong Order For Learnyounode Node.js Tutorial"