gitmyhub

forever

JavaScript ★ 14k updated 3y ago

A simple CLI tool for ensuring that a given script runs continuously (i.e. forever)

Forever is a command-line tool that keeps a Node.js script running continuously by automatically restarting it whenever it crashes or exits, running the process as a background daemon.

JavaScriptNode.jsnpmsetup: easycomplexity 2/5

Forever is a command-line tool for Node.js that keeps a script running at all times. If the script crashes or exits, forever detects this and starts it again automatically. You install it once globally via npm, then use it to wrap any script you want to keep alive.

The basic workflow is simple: instead of running "node app.js" directly, you run "forever start app.js". The process moves to the background as a daemon, and forever watches over it. If it dies, forever restarts it. You can see all running scripts with "forever list", stop them by name or ID, restart them, or tail their log files, all from the command line.

Beyond simple restarts, the tool offers a range of options. You can cap how many times a script is allowed to restart before giving up, redirect its output and error streams to log files, watch the source directory for file changes and restart on edits, and control the minimum uptime a process must reach before forever stops treating it as a crash loop. Configuration can be passed as command-line flags or written into a JSON file, which also lets you define multiple apps to start together.

The README notes that this project is now maintained by the community rather than by an active core team. For new projects, the authors themselves suggest looking at alternatives like pm2 or nodemon, which have more active maintenance and broader feature sets.

Forever also exposes a programmatic API, though the README recommends installing the companion package forever-monitor for that use case rather than the main CLI package. The programmatic side is geared toward developers who want process-management behavior built into their own Node.js applications rather than managed from a terminal.

Where it fits