@wll8/process-manager

1.0.4 • Public • Published

A simple node subroutine manager. It includes functions such as manual or automatic process restart and process communication.

Example

const { ProcessManager } = require(`@wll8/process-manager`);
const cp = new ProcessManager([`${__dirname}/child.js`, `arg`, `arg`]);
cp.send(`text`);
cp.on(`close`, () => {
  console.log(`close`);
});

Use

  • 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,
};

cp.on

  • message
    Listen for messages sent by the child process

  • stdout
    Listen to stdout output

  • stderr
    Listen to stderr output

  • close
    Monitor subprocess shutdown completion

cp.send

Send a message to the child process

cp.kill

Close child process without restarting

cp.start

Manually start the process

cp.reboot

Manually kill the process and restart the process

cp.getChild

Get the current process instance

license

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @wll8/process-manager

      Weekly Downloads

      20

      Version

      1.0.4

      License

      MIT

      Unpacked Size

      6.45 kB

      Total Files

      5

      Last publish

      Collaborators

      • wll8