Forever is a node package used to run Node.js applications with monitoring. It keeps the server alive even when the server crash/stops. When the Node server is stopped due to some error or exception it will automatically start the server. It runs like a daemon on ubuntu Linux. So if the application dies forever brings it back. It will automatically start the server (Node.js application) when our linux server starts and ensure it stays running.

 Forever Setup

Forever can be installed using npm command. To install it globally

sudo npm -g install forever

The usage options for Forever expose four simple command line tasks: start, stop, stopall, list.

forever [start | stop | stopall | list] [options] script [script options]

Forever Options:

start    : Start script as a daemon
stop     : Stop the daemon script
stopall : Stop all running forever script
list      : List all running forever script

Now start server using forever command instead of node.

forever start server.js

To check server has started or not?

forever list
 [0] server.js [ 24597, 24596 ]

To kill that process we need simply

forever stop 0

More about its options read documentation available on Github and Npm website.

Leave Comment

Your email address will not be published. Required fields are marked *

en_USEnglish
en_USEnglish