Restart a Node.js app when the server reboots

I had some issues when I first setup my Debian VPS for my node.js app over at when the ISP rebooted my server a couple of times unexpectedly and my node app didn’t come back online.

I didn’t find many options out there, so I wrote a node-startup script (available on github) that can be used in /etc/init.d and will restart your node.js app when the server reboots.

First, clone the repo from github:

Edit the node-app script with your settings for node path, node environment (ie: production or development), path to application directory (where your app.js is – this is also NODE_APP variable), and a path to a pid file.

By default, it expects the pid file to be in /var/www/ and your log file to be in /var/www/

Copy the startup script node-app to your /etc/init.d directory

Test that it all works:

Add node-app to the default runlevels

Finally, reboot to be sure app starts automatically

If you are using mongodb, redis, or nginx, you want to add those to your default run-level as well.

Here’s the link to the github project: