Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


Spawn a process and restart it if it crashes

Subscribe to updates I use respawn

Statistics on respawn

Number of watchers on Github 232
Number of open issues 8
Average time to close an issue 28 days
Main language JavaScript
Average time to merge a PR about 19 hours
Open pull requests 5+
Closed pull requests 0+
Last commit over 2 years ago
Repo Created almost 6 years ago
Repo Last Updated over 1 year ago
Size 44 KB
Organization / Authormafintosh
Page Updated
Do you use respawn? Leave a review!
View open issues (8)
View respawn activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating respawn for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


Spawn a process and restart it if it crashes.

npm install respawn

Build Status


It is easy to use

var respawn = require('respawn')

var monitor = respawn(['node', 'server.js'], {
  name: 'test',          // set monitor name
  env: {ENV_VAR:'test'}, // set env vars
  cwd: '.',              // set cwd
  maxRestarts:10,        // how many restarts are allowed within 60s
                         // or -1 for infinite restarts
  sleep:1000,            // time to sleep between restarts,
  kill:30000,            // wait 30s before force killing after stopping
  stdio: [...],          // forward stdio options
  fork: true             // fork instead of spawn

monitor.start() // spawn and watch

Optionally you can specify the command to to spawn in the option map as command: [...]

Per default respawn will restart you app indefinitely. To set a max restart limit set the maxRestarts option.

If sleep is an array of numbers it will use the value at the position of the current number of restarts as the timeout value. If the number of restarts exceed the length of the array it will use the last value in the array until it hits the maxRestarts.

sleep: [1000, 60000, 60000, 12000, 1000] will wait 1000ms before retrying, then it will wait 60000 before the next retry and so forth.

If sleep is a function it will be passed the number of times (including this one) that the app has been restarted (i.e. first time will be called with 1, second time 2 etc.) and should return a time in milliseconds.


  • monitor.start() Starts the monitor

  • monitor.stop(cb) Stops the monitor (kills the process if its running with SIGTERM)

  • monitor.status Get the current monitor status. Available values are running, stopping, stopped, crashed and sleeping


  • monitor.on('start') The monitor has started

  • monitor.on('stop') The monitor has fully stopped and the process is killed

  • monitor.on('crash') The monitor has crashed (too many restarts or spawn error).

  • monitor.on('sleep') monitor is sleeping

  • monitor.on('spawn', process) New child process has been spawned

  • monitor.on('exit', code, signal) child process has exited

  • monitor.on('stdout', data) child process stdout has emitted data

  • monitor.on('stderr', data) child process stderr has emitted data

  • monitor.on('warn', err) child process has emitted an error

Graceful restart

To do graceful restart simply have your app stop gracefully when receiving SIGTERM and do

// graceful restart (do not wait for old process to die)

// hard restart (wait for old process to die)
monitor.stop(function() {



respawn open issues Ask a question     (View All Issues)
  • over 3 years Span EPERM Issue
  • almost 6 years Clustering
respawn open pull requests (View All Pulls)
  • Added monitors list
  • add cluster support
  • Added Crashes Counter & Custom Data Field
  • #22 passing execPath and execArgs to child_process.fork
  • Fix crash count not adding correctly
respawn questions on Stackoverflow (View All Questions)
  • How do I respawn the rectangle after contact in a random location in Slick2D?
  • Stop the Collide Values and respawn the object
  • Upstart respawn child process
  • Corona : How can i make object move vertically up and respawn randomly at x axis
  • uwsgi + django slow respawn/reload/restart
  • How to respawn enemy in processing
  • inittab respawn of Node.js too fast
  • Unity object respawn keeps it moving
  • respawn service Debian Jessie without inittab
  • How to limit the number of instances UpStart can simultaneously start or respawn
  • How to respawn the sprites for a new level/ or generate a new level, once all the sprites have been picked up
  • BASH: How to exit from a script, trigging until to respawn the script
  • Using different console for respawn process in inittab on embedded device
  • Process respawn and signal handling in PHP
  • How do I make my enemySprite respawn as new bad guy once its been killed?
  • Falling Respawn
  • Respawn Prefab After 5 Second's Error?
  • Respawn destroyed object in Unity
  • Unity 2D | How To Make A Character Respawn?
  • Upstart script for bitcoind, respawn feature
  • Respawn an enemy prefab after its destroyed
  • Unity3D - unable to respawn an object after it has been destroyed
  • Unity Multiplayer Respawn Calling C# from Unityscript
  • How to send an email notification on upstart reaching respawn limit?
  • How To Respawn A Prefab After 5 Second's?
  • Can upstart expect/respawn be used on processes that fork more than twice?
  • Automatic respawn fastcgi process by nginx?
  • Schedulling respawn returns error in collision detection
  • How Can I Reset my Car Movement if I return to my last respawn point?
  • Unity - How to respawn a Gameobject after destroy
respawn list of languages used
Other projects in JavaScript