Reputation: 1153
I've been looking into Node.js and it seems like it offers a whole new dimension to web server development. However, I'm confused about the asynchronous processing that is held up as its main point of awesomeness.
Does the runtime take care of all the asynchronous processing automatically or does it simply offer APIs that you can use to build asynchronous apps? Or perhaps both?
Upvotes: 0
Views: 46
Reputation: 1276
The Node.js API is designed around asynchronous I/O processing. You will still have to develop using async patterns. It is not "automatic" in the sense that the following synchronous code would work in Node.js: results = db.query();
Upvotes: 0
Reputation: 94
Node.js is good for asynchronous model since it uses callback functions will be event-driven. Node.js is single threaded so it can manage resources more efficiently and in a very simple manner for asynchronous model.
Node.js provides many asynchronous modules/APIs but there are synchronous APIs too.
But you can also write synchronous functions in node.js too. e.g. fs can be written synchronously or asynchronously.
My answer to you question will be: It is the way how the code is written.
You can also write async code in other languages like Java but the resource management will be very complex since you need to handle mulit-thread environment.
But David is correct about the even driven loop.
Upvotes: 1
Reputation: 659
automatically. The Event Loop provides async processing of your function calls
Callback functions (or promises) let you break up your logic into separate (non-blocking) chunks that are added to the Event Loop's queue, so your program flow ends up being a bunch of async function calls
Upvotes: 1