Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

84 lines (63 sloc) 2.687 kB


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


Installing npm (node package manager)

  curl | sh

Installing http-agent

  [sudo] npm install forever


There are two distinct ways to use forever: through the command line interface, or by requiring the forever module in your own code.

Using forever from the command line

You can use forever to run any kind of script continuously (whether it is written in node.js or not). The usage options are simple:

  usage: forever [FILE, ...] [options]

    -m MAX            Only run the specified script MAX times
    -s, --silent      Run the child script silencing stdout and stderr
    -o, OUTFILE       Logs stdout from child script to OUTFILE
    -e, ERRFILE       Logs stderr from child script to ERRFILE
    -h, --help        You're staring at it

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

  forever samples/error-on-timer.js -m 5

Using forever from node.js

You can also use forever from inside your own node.js code.

  var forever = require('forever');
  var child = new (forever.Forever)('your-filename.js'), {
    max: 3,
    silent: true,
    options: []
  child.on('exit', this.callback);;

Options available when using Forever in node.js

There are several options that you should be aware of when using forever:

    'max': 10,                  // Sets the maximum number of times a given script should run
    'forever': true,            // Indicates that this script should run forever 
    'silent': true,             // Silences the output from stdout and stderr in the parent process
    'outfile': 'path/to/file',  // Path to log output from child stdout
    'errfile': 'path/to/file',  // Path to log output from child stderr

Events available when using Forever in node.js

Each forever object is an instance of the node.js core EventEmitter. There are several core events that you can listen for:

  • restart [err, forever]: Raised each time the target script is restarted
  • exit [err, forever]: Raised when the call to completes
  • stdout [err, data]: Raised when data is received from the child process' stdout
  • stderr [err, data]: Raised when data is received from the child process' stderr

Run Tests

  vows test/*-test.js --spec

Author: Charlie Robbins

Contributors: Fedor Indutny

Jump to Line
Something went wrong with that request. Please try again.