forever vs nodemon vs pm2 vs supervisor
Node.js Process Management and Development Workflow Tools
forevernodemonpm2supervisor

Node.js Process Management and Development Workflow Tools

forever, nodemon, pm2, and supervisor are utilities designed to keep Node.js applications running continuously. They handle process crashes, restarts, and file changes, but serve different stages of the development lifecycle. nodemon is primarily a development tool that restarts apps when source code changes. pm2 is a robust production process manager with clustering, logging, and monitoring. forever is a simpler legacy tool for keeping scripts alive in the background. supervisor is an older utility similar to nodemon but is largely considered deprecated or unmaintained in modern workflows.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
forever013,865150 kB342-MIT
nodemon026,694219 kB916 days agoMIT
pm2042,974838 kB1,0903 months agoAGPL-3.0
supervisor03,738-539 years agoMIT

Node.js Process Management: forever vs nodemon vs pm2 vs supervisor

Keeping a Node.js application running reliably is a fundamental requirement for both development and production. forever, nodemon, pm2, and supervisor all address this need, but they target different stages of the lifecycle. Some are built for the feedback loop of coding, while others are engineered for uptime and scale. Let's compare how they handle process lifecycle, configuration, and production readiness.

🔄 Restart Logic: File Changes vs Crashes

nodemon is designed for development. It watches your file system and restarts the process when code changes are detected. It is not intended to manage production crashes.

# nodemon: Watch and restart on file change
nodemon server.js
// nodemon: Config via nodemon.json
{
  "watch": ["src"],
  "ext": "ts js",
  "exec": "ts-node"
}

pm2 focuses on production uptime. It restarts processes if they crash or run out of memory, and it can also watch files (though this is discouraged in production).

# pm2: Start and keep alive
pm2 start server.js
// pm2: Config via ecosystem.config.js
module.exports = {
  apps: [{
    name: "app",
    script: "server.js",
    instances: 4,
    exec_mode: "cluster"
  }]
}

forever keeps a script running continuously. If the script exits, forever restarts it. It does not inherently watch for file changes without extra flags or tools.

# forever: Run script continuously
forever start server.js
// forever: Programmatic usage
const forever = require('forever');

forever.start('server.js', {
  silent: true,
  max: 3
});

supervisor watches for changes and restarts the node process, similar to nodemon. It is an older approach to the same problem.

# supervisor: Watch and run
supervisor server.js
// supervisor: No standard config file support like nodemon/pm2
// Typically run via CLI flags only
// supervisor -w lib server.js

🏭 Production Readiness: Clustering and Scaling

pm2 is the only tool in this list built for horizontal scaling on a single server. It supports cluster mode to utilize all CPU cores.

# pm2: Cluster mode for multi-core utilization
pm2 start server.js -i max

forever runs a single instance per command. To scale, you must manage multiple forever processes manually or via scripts.

# forever: Single instance management
forever start -l log.txt server.js

nodemon runs a single instance. It is not designed to manage load or multiple workers.

# nodemon: Single instance for dev
nodemon server.js

supervisor runs a single instance. It lacks built-in clustering capabilities.

# supervisor: Single instance
supervisor server.js

🛠️ Configuration and Ecosystem

pm2 offers a comprehensive ecosystem file for managing multiple applications, environments, and deployment hooks.

// pm2: ecosystem.config.js supports env variables
module.exports = {
  apps: [{
    name: "api",
    script: "./app.js",
    env: {
      NODE_ENV: "development"
    },
    env_production: {
      NODE_ENV: "production"
    }
  }]
}

nodemon uses a simple JSON config for watch patterns and execution commands.

// nodemon: nodemon.json
{
  "ignore": ["test/*", "docs/*"],
  "delay": 2500
}

forever relies mostly on CLI flags, though it can be used programmatically.

# forever: CLI flags for logging
forever start -o out.log -e err.log -l forever.log server.js

supervisor has minimal configuration options, mostly handled through command line arguments.

# supervisor: CLI arguments
supervisor -w config -n error server.js

⚠️ Maintenance and Status

nodemon is actively maintained and is the de facto standard for Node.js development. It receives regular updates for compatibility with new Node versions.

pm2 is actively maintained and widely used in enterprise production environments. It has a large ecosystem of modules and integrations.

forever is maintained but sees less active development compared to pm2. It is stable but lacks modern features like built-in monitoring dashboards.

supervisor is largely considered abandoned or legacy. It has not seen significant updates in years and is not recommended for new projects.

📊 Summary Table

Featurenodemonpm2foreversupervisor
Primary UseDevelopmentProductionProduction/LegacyDevelopment (Legacy)
Auto RestartOn File ChangeOn Crash/ExitOn Crash/ExitOn File Change/Crash
Clustering❌ No✅ Yes❌ No❌ No
Config Filenodemon.jsonecosystem.config.jsCLI/CodeCLI
Status✅ Active✅ Active⚠️ Stable❌ Legacy/Abandoned

💡 The Big Picture

nodemon is your daily driver for writing code. It saves time by automating restarts during development. Never use it to host a live site.

pm2 is your production engine. It ensures your app stays online, scales across cores, and provides logs and metrics. It is the professional choice for hosting.

forever is a reliable fallback for simple scripts or legacy systems where installing pm2 is not feasible. It works, but it shows its age.

supervisor should be avoided. It solves the same problem as nodemon but without the active support or feature parity. Stick to nodemon for development.

Final Thought: Your tooling should match your environment. Use nodemon to build fast, and pm2 to run stable. Leave supervisor in the past and use forever only when simplicity outweighs feature needs.

How to Choose: forever vs nodemon vs pm2 vs supervisor

  • forever:

    Choose forever if you need a lightweight, simple solution to keep a script running on a legacy server without complex features. It is suitable for small, single-instance scripts where advanced monitoring or clustering is not required. However, for modern production environments, more robust tools are generally preferred.

  • nodemon:

    Choose nodemon for local development when you need your server to automatically restart upon detecting file changes. It is the industry standard for development workflows due to its ease of configuration and wide plugin support. Do not use it for production hosting as it lacks process management features like clustering.

  • pm2:

    Choose pm2 for production environments where you need process management, load balancing via clustering, and zero-downtime reloads. It is ideal for applications requiring high availability, log management, and monitoring dashboards. It handles both simple scripts and complex microservice architectures effectively.

  • supervisor:

    Avoid choosing supervisor for new projects as it is largely unmaintained and considered legacy technology. While it functions similarly to nodemon by restarting on changes, it lacks the active community support and modern feature set of current alternatives. Use nodemon instead for development needs.

README for forever

forever

Join the chat at https://gitter.im/foreverjs/forever

Version npmnpm DownloadsBuild StatusDependenciesInline docs

NPM

A simple CLI tool for ensuring that a given script runs continuously (i.e. forever). Note that this project currently fully depends on the community for implementing fixes and new features. For new installations we encourage you to use pm2 or nodemon

Installation

  $ [sudo] npm install forever -g

Note: If you are using forever programmatically you should install forever-monitor.

  $ cd /path/to/your/project
  $ [sudo] npm install forever-monitor

Usage

There are two ways to use forever: through the command line or by using forever in your code. Note: If you are using forever programatically you should install forever-monitor.

Command Line Usage

You can use forever to run scripts continuously (whether it is written in node.js or not).

Example

forever start app.js

Options

  $ forever --help
  usage: forever [action] [options] SCRIPT [script-options]

  Monitors the script specified in the current process or as a daemon

  actions:
    start               Start SCRIPT as a daemon
    stop                Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script
    stopall             Stop all running forever scripts
    restart             Restart the daemon SCRIPT
    restartall          Restart all running forever scripts
    list                List all running forever scripts
    config              Lists all forever user configuration
    set <key> <val>     Sets the specified forever config <key>
    clear <key>         Clears the specified forever config <key>
    logs                Lists log files for all forever processes
    logs <script|index> Tails the logs for <script|index>
    columns add <col>   Adds the specified column to the output in `forever list`. Supported columns: 'uid', 'command', 'script', 'forever', 'pid', 'id', 'logfile', 'uptime'
    columns rm <col>    Removed the specified column from the output in `forever list`
    columns set <cols>  Set all columns for the output in `forever list`
    columns reset       Resets all columns to defaults for the output in `forever list`
    cleanlogs           [CAREFUL] Deletes all historical forever log files

  options:
    -m  MAX          Only run the specified script MAX times
    -l  LOGFILE      Logs the forever output to LOGFILE
    -o  OUTFILE      Logs stdout from child script to OUTFILE
    -e  ERRFILE      Logs stderr from child script to ERRFILE
    -p  PATH         Base path for all forever related files (pid files, etc.)
    -c  COMMAND      COMMAND to execute (defaults to node)
    -a, --append     Append logs
    -f, --fifo       Stream logs to stdout
    -n, --number     Number of log lines to print
    --pidFile        The pid file
    --uid            DEPRECATED. Process uid, useful as a namespace for processes (must wrap in a string)
                     e.g. forever start --uid "production" app.js
                         forever stop production
    --id             DEPRECATED. Process id, similar to uid, useful as a namespace for processes (must wrap in a string)
                     e.g. forever start --id "test" app.js
                         forever stop test
    --sourceDir      The source directory for which SCRIPT is relative to
    --workingDir     The working directory in which SCRIPT will execute
    --minUptime      Minimum uptime (millis) for a script to not be considered "spinning"
    --spinSleepTime  Time to wait (millis) between launches of a spinning script.
    --colors         --no-colors will disable output coloring
    --plain          Disable command line colors
    -d, --debug      Forces forever to log debug output
    -v, --verbose    Turns on the verbose messages from Forever
    -s, --silent     Run the child script silencing stdout and stderr
    -w, --watch      Watch for file changes
    --watchDirectory Top-level directory to watch from
    --watchIgnore    To ignore pattern when watch is enabled (multiple option is allowed)
    -t, --killTree   Kills the entire child process tree on `stop`
    --killSignal     Support exit signal customization (default is SIGKILL),
                     used for restarting script gracefully e.g. --killSignal=SIGTERM
                     Any console output generated after calling `forever stop/stopall` will not appear in the logs
    -h, --help       You're staring at it

  [Long Running Process]
    The forever process will continue to run outputting log messages to the console.
    ex. forever -o out.log -e err.log my-script.js

  [Daemon]
    The forever process will run as a daemon which will make the target process start
    in the background. This is extremely useful for remote starting simple node.js scripts
    without using nohup. It is recommended to run start with -o -l, & -e.
    ex. forever start -l forever.log -o out.log -e err.log my-daemon.js
        forever stop my-daemon.js

There are several examples designed to test the fault tolerance of forever. Here's a simple usage example:

  $ forever -m 5 examples/error-on-timer.js

JSON Configuration Files

In addition to passing forever the path to a script (along with accompanying options, described above), you may also pass forever the path to a JSON file containing these options. For example, consider an application with the following file structure:

.
├── forever
│   └── development.json
└── index.js

// forever/development.json
{
	// Comments are supported
    "uid": "app",
    "append": true,
    "watch": true,
    "script": "index.js",
    "sourceDir": "/home/myuser/app",
    "logFile": "/home/myuser/logs/forever.log",
    "outFile": "/home/myuser/logs/out.log",
    "errFile": "/home/myuser/logs/error.log"
}

This application could be started with forever, as shown below:

$ forever start ./forever/development.json

Absolute paths to such configuration files are also supported:

$ forever start /home/myuser/app/forever/development.json

Note: Forever parses JSON configuration files using shush, allowing the use of in-line comments within such files.

Multi-App Configuration Files

JSON configuration files can also be used to define the startup options for multiple applications, as shown below.

[
  {
    // App1
    "uid": "app1",
    "append": true,
    "watch": true,
    "script": "index.js",
    "sourceDir": "/home/myuser/app1"
  },
  {
    // App2
    "uid": "app2",
    "append": true,
    "watch": true,
    "script": "index.js",
    "sourceDir": "/home/myuser/app2",
    "args": ["--port", "8081"]
  }
]

Using In Your Code

The forever module exposes some useful methods to use in your code. Each method returns an instance of an EventEmitter which emits when complete. See the forever cli commands for sample usage.

Remark: As of forever@0.6.0 processes will not automatically be available in forever.list(). In order to get your processes into forever.list() or forever list you must instantiate the forever socket server:

  forever.startServer(child);

This method takes multiple forever.Monitor instances which are defined in the forever-monitor dependency.

forever.load (config)

Synchronously sets the specified configuration (config) for the forever module. There are two important options:

OptionDescription  Default
rootDirectory to put all default forever log filesforever.root
pidPathDirectory to put all forever *.pid files[root]/pids
sockPathDirectory for sockets for IPC between workers[root]/sock
loglengthNumber of logs to return in forever tail100
columnsArray of columns to display when format is trueforever.config.get('columns')
debugBoolean value indicating to run in debug modefalse
streamBoolean value indicating if logs will be streamedfalse

forever.start (file, options)

Starts a script with forever. The options object is what is expected by the Monitor of forever-monitor.

forever.startDaemon (file, options)

Starts a script with forever as a daemon. WARNING: Will daemonize the current process. The options object is what is expected by the Monitor of forever-monitor.

forever.stop (index)

Stops the forever daemon script at the specified index. These indices are the same as those returned by forever.list(). This method returns an EventEmitter that raises the 'stop' event when complete.

forever.stopAll (format)

Stops all forever scripts currently running. This method returns an EventEmitter that raises the 'stopAll' event when complete.

The format parameter is a boolean value indicating whether the returned values should be formatted according to the configured columns which can set with forever columns or programmatically forever.config.set('columns').

forever.list (format, callback)

Returns a list of metadata objects about each process that is being run using forever. This method will return the list of metadata as such. Only processes which have invoked forever.startServer() will be available from forever.list()

The format parameter is a boolean value indicating whether the returned values should be formatted according to the configured columns which can set with forever columns or programmatically forever.config.set('columns').

forever.tail (target, options, callback)

Responds with the logs from the target script(s) from tail. There are two options:

  • length (numeric): is is used as the -n parameter to tail.
  • stream (boolean): is is used as the -f parameter to tail.

forever.cleanUp ()

Cleans up any extraneous forever *.pid files that are on the target system. This method returns an EventEmitter that raises the 'cleanUp' event when complete.

forever.cleanLogsSync (processes)

Removes all log files from the root forever directory that do not belong to current running forever processes. Processes are the value returned from Monitor.data in forever-monitor.

forever.startServer (monitor0, monitor1, ..., monitorN)

Starts the forever HTTP server for communication with the forever CLI. NOTE: This will change your process.title. This method takes multiple forever.Monitor instances which are defined in the forever-monitor dependency.

Logging and output file locations

By default forever places all of the files it needs into /$HOME/.forever. If you would like to change that location just set the FOREVER_ROOT environment variable when you are running forever:

FOREVER_ROOT=/etc/forever forever start index.js

Make sure that the user running the process has the appropriate privileges to read & write to this directory.

Run Tests

  $ npm test

License: MIT

Author: Charlie Robbins

Maintainer: Igor Savin

Contributors: Fedor Indutny, James Halliday, Charlie McConnell, Maciej Malecki, John Lancaster