A simple node subroutine manager. It includes functions such as manual or automatic process restart and process communication.
const { ProcessManager } = require(`@wll8/process-manager`);
const cp = new ProcessManager([`${__dirname}/child.js`, `arg`, `arg`]);
cp.send(`text`);
cp.on(`close`, () => {
console.log(`close`);
});
- type: object
option = {
bin: `node`, // The first parameter of nodejs spawn
arg: [], // The second parameter of nodejs spawn
autoReStart: true, // Automatically restart child processes
autoReStartTime: 1000, // Restart interval, milliseconds
stdout = (chunk, encoding, cb) => { process.stdout.write(chunk), cb(null, chunk) },
stderr = (chunk, encoding, cb) => { process.stderr.write(chunk), cb(null, chunk) },
spawnOption: {},
};
- type: array
option = {
...option,
arg: array,
};
-
message
Listen for messages sent by the child process -
stdout
Listen to stdout output -
stderr
Listen to stderr output -
close
Monitor subprocess shutdown completion
Send a message to the child process
Close child process without restarting
Manually start the process
Manually kill the process and restart the process
Get the current process instance
MIT