Last Updated: February 25, 2016
·
2.564K
· reezer

Run your service forever (and more)

Ever wanted to deploy your node.js application on a server, but all you did was using nohup node script.js &, because alternative solutions appeared to be to hard`

There is a nice tool from the nodejitsu folks called forever.

It is really simple to use

forever script.js

This will start your script using node and should it crash restart it, using sane defaults about when and how quickly these restarts happen.

Using coffee or not even node at all? Just use the -c (--command) parameter.

forever -c coffee script.coffee

Using this option also allows forever to be used with non-node applications.

But wait there is more! Ever started an application and wished there was some straight forward way to restart your application on code change? Forever has yet another switch for this. -w (or --watch)

forever -w script.js

This is all nice, but it's still nothing compared to a full-blown deamon, right? Well, no. forever offers even more. Once your app is running using forever you can use forever, like this:

forever stop script.js
forever start script.js
forever restart script.js

It also allows you to specify where logs (stderr/stdout) are going and much more. The nice thing about forever is that it scales well with your needs, always while the only requirement for getting it up and running is this:

npm -g install forever
forever myscript.js

1 Response
Add your response

Yeah, it's ace and forever-monitor means you have all that goodness programmatically too

over 1 year ago ·