Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

respawn

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

respawn

Spawn a process and restart it if it crashes

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

respawn

Spawn a process and restart it if it crashes.

npm install respawn

Build Status

Usage

It is easy to use

var respawn = require('respawn');

var monitor = respawn(['node', 'server.js'], {
	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,
	stdio: [...]           // forward stdio options
});

monitor.start(); // spawn and watch

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

API

  • 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 and sleeping

Events

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

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

  • 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)
monitor.stop();
monitor.start();

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

License

MIT

Keywords

FAQs

Package last updated on 22 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc