README
@nore/pm
A cross-platform Node.js process manager.
Install
npm install @nore/pm
Usage
import PM from "@nore/pm";
const command = ["node", "script.js", "--debug"];
const options = { cwd: "/path/to/directory", restartLimit: 2 };
const pm = new PM(command, options);
Options:
killTimeout
– wait?
milliseconds for the process to exit else send a SIGKILL, default:30000
restartDelay
– wait?
milliseconds between restarts, default:1000
restartLimit
– the number of times a process can be restarted automatically; settingnull
will restart it indefinitely, default:0
- other options are directly passed to the spawned process, follow the official documentation
API
await
pm.start()
– start the processawait
pm.stop()
– stop the processawait
pm.restart()
– restart the processpm.on('start' () => {})
– emitted when the process is startedpm.on('stop' () => {})
– emitted when the process is stoppedpm.on('spawn', (process) => {})
– emitted when a new process was spawnedpm.on('error', (error) => {})
– emitted on process errorpm.on('exit', (code, signal) => {})
– emitted on process exitpm.status
– the status of the process
pm.status
:
initial
– the inital state after creating thepm
instancerunning
– after the process was startedsleeping
– during the delay period while the process is restartingstopping
– during the.stop()
processstopped
– after the.stop()
was completedcrashed
– process crashed on error or exited without being stopped