Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wll8/process-manager
A simple node subroutine manager.
https://github.com/wll8/process-manager
Last synced: about 5 hours ago
JSON representation
A simple node subroutine manager.
- Host: GitHub
- URL: https://github.com/wll8/process-manager
- Owner: wll8
- Created: 2023-03-29T07:16:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-06T08:59:55.000Z (3 months ago)
- Last Synced: 2024-08-06T10:53:11.303Z (3 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
A simple node subroutine manager. It includes functions such as manual or automatic process restart and process communication.
## Example
```js
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
```js
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) => cb(),
stderr: (chunk, encoding, cb) => cb(),
spawnOption: {},
};
```- type: array
```js
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