Search code examples
javascriptnode.jswebsocketsocket.ioforever

Running node.js script with forever


I'm running a node script with forever and am curious about how reliable it is and if I should build some other kind of checkup if the script is still running. I'm using this command:

forever start server.js

The server is used as my websocket server and has to run even though there are errors thrown that would normally stop the script. I've made some tests and it seems to work, but it would be great to hear from someone who is using this combination for a while about how reliable this will really be in a production environment.


Solution

  • I'm running forever in a production environment and love it personally. I use the node server to process images using ImageMagick. Occasionally I'll get an ENOMEM error (out of memory) and Node crashes. (I'm guessing this is a memory leak in my script I haven't tracked down yet) When this happens, Forever kicks right in and within seconds the server is back up. I have the browser return a message to the user asking them to try again - they do and it processes just fine. I've seen other random errors happen as well, mainly during development, and Forever has caught those as well and rebooted the Node server without fail. I can't recall a time that Node has crashed and the server never rebooted, so it does what it should.

    Also what is great is in your Node scripts if you do a console.log() it outputs to the forever log. I'll do a tail on this often times to keep a check on what is happening on the server, or even just look back at the logs from time to time to see how its performing. It'll tell you in there if/when Forever rebotted the server.

    Good luck!