If we use
node to run Node.js script, it will block the current shell until it crashes or is forced to exit with Ctrl-C. But sometimes we might need to run this service in background or manage the Node.js
The traditional way is to use
$ nohup node hello.js > output.log &
Or you can choose some libraries such as daemon.node. So, if we already has the way to run service in background, what’s the benefit of using Forever?
Forever is not just for running script in background, it can automatically restart the service when it stop unexpectedly.
Let’s install Forever and check it’s help document.
$ sudo npm install forever
$ forever --help
If you want to run your script in background, just use
forever start instead of
$ forever start hello.js
Info: Forever processing file: hello.js
When you need to stope the running process, you can use
forever list to see all your running process.
$ forever list
info: Forever processes running
data: uid command script forever pid logfile uptime
data:  mn0M /usr/local/bin/node hellp.js 86298 86299 /Users/evahsieh/.forever/mn0M.log 0:0:0:9.207
$ forever stop 0