cgn3eg
Last Updated: February 25, 2016
·
1.757K
· reezer
3d8f95f51401a52705432b7d3986f99a

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
Say Thanks
Respond

1 Response
Add your response

9105
3f23a52c7bc87296e96b5a05547da0e0

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

over 1 year ago ·