Installations
npm install respawn
Developer Guide
Typescript
No
Module System
N/A
Node Version
10.15.0
NPM Version
6.4.1
Score
74.2
Supply Chain
95.8
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
mafintosh
Download Statistics
Total Downloads
1,399,027
Last Day
175
Last Week
1,410
Last Month
8,004
Last Year
123,587
GitHub Statistics
255 Stars
90 Commits
37 Forks
10 Watching
1 Branches
9 Contributors
Bundle Size
12.49 kB
Minified
4.33 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.6.0
Package Id
respawn@2.6.0
Size
5.20 kB
NPM Version
6.4.1
Node Version
10.15.0
Publised On
14 Jan 2019
Total Downloads
Cumulative downloads
Total Downloads
1,399,027
Last day
-39.9%
175
Compared to previous day
Last week
-12.3%
1,410
Compared to previous week
Last month
-16.9%
8,004
Compared to previous month
Last year
-31.8%
123,587
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
respawn
Spawn a process and restart it if it crashes.
npm install respawn
Usage
It is easy to use
1var respawn = require('respawn') 2 3var monitor = respawn(['node', 'server.js'], { 4 name: 'test', // set monitor name 5 env: {ENV_VAR:'test'}, // set env vars 6 cwd: '.', // set cwd 7 maxRestarts:10, // how many restarts are allowed within 60s 8 // or -1 for infinite restarts 9 sleep:1000, // time to sleep between restarts, 10 kill:30000, // wait 30s before force killing after stopping 11 stdio: [...], // forward stdio options 12 fork: true // fork instead of spawn 13}) 14 15monitor.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.
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 arerunning
,stopping
,stopped
,crashed
andsleeping
Events
-
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
1// graceful restart (do not wait for old process to die) 2monitor.stop() 3monitor.start() 4 5// hard restart (wait for old process to die) 6monitor.stop(function() { 7 monitor.start() 8})
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 8/24 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 14 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More