Tuesday, September 8, 2015

NodeJS Server Uptime

In NodeJS, everything is handled by a single javascript thread. So if an error get occurred, the server will stop.But this won't happen in traditional web servers. Because, in traditional web servers, there is a thread pool to handle requests. For each request, a thread will be assigned. If there is an error, that particular thread will discarded and new thread will be allocated.
In the following code, there are some invalid code.
In the first request, error get occurred and then server won't process any more requests.
Using forever we can automatically restart NodeJS server. First install forever like below.
Now, run above code using following command.
In the first client request server will crash. But forever will restart the server again. Forever is not a better way to handle errors in NodeJS application. But this is useful as a back for the unexpected.

No comments:

Post a Comment