forever
Run Node.js scripts continuously in the background
TLDR
Start running a file forever (as a daemon)
List running "forever" processes (along with IDs and other details of "forever" processes)
Stop a running "forever" process
SYNOPSIS
forever [options] script.js [script-options]
PARAMETERS
-m
Sets the maximum number of times a script should be restarted.
-l
Logs forever output to
-o
Logs stdout from child script to
-e
Logs stderr from child script to
-p
Sets the path to store pid files (default: $HOME/.forever).
-c
Sets the command to execute (default: node).
-a
Appends logs to existing log files.
-f
Forces forever to run when the log file exists.
-n
Sets the number of instances to run.
-w
Watches the script for file changes.
-v
Increases verbosity.
-h
Displays help.
-V
Displays the version of forever.
start
Starts the specified script.
stop
Stops the specified script or process ID.
restart
Restarts the specified script or process ID.
list
Lists all running forever processes.
clean
Removes all stale pid files.
DESCRIPTION
forever is a NodeJS-based command-line tool designed to ensure that a given script runs continuously, even if it crashes or exits unexpectedly.
It achieves this by monitoring the process and automatically restarting it whenever it terminates. This makes it particularly useful for deploying and managing long-running applications, such as Node.js servers, where constant uptime is critical. forever simplifies process management by providing a convenient way to start, stop, restart, and monitor these applications. It eliminates the need for manually starting the application after each crash or system reboot. It is important to consider other process managers like systemd or pm2 as well, which provide more features like logging and process monitoring.
CAVEATS
forever relies on NodeJS. Ensure NodeJS is installed and configured correctly.
The script will be restarted even if crashed due to programming errors, so it is not a replacement for proper error handling.
USAGE EXAMPLES
Example: forever start myapp.js
Starts myapp.js and restarts it if it crashes.
Example: forever stop myapp.js
Stops myapp.js
Example: forever list
Lists all processes managed by forever
HISTORY
forever was created as a convenient way to keep Node.js applications running continuously.
Over time, it has gained popularity as a simple process manager, primarily focused on restarting applications on crashes.
SEE ALSO
systemd(1), pm2