Use node.js as http server

apachenode.jsserver

I know what node.js is & what it does.

What I really want to know is how does it work as an http server?

A server like apache gets a request, fork a process, allocate memory to process, handle the request & release the process after it is completed. If we get thousands of http requests at a time, then apache waits for the the process queue to release process.

How does node.js with a single threaded environment handles so many http requests. All the incoming requests are given their own event loop. All these event loops share same memory.

How does using node.js to handle millions of http requests more scalable than using apache?

Best Answer

key point would be not forking a new process for each request,

node.js assumes your process is heavily IO bound (reasonable for a webserver with separate DB)

this means that each time you are waiting on the database to return the next result another request is being handled

Related Topic