Manager for handling child process, automatically restart them, sending message etc
npm install node-child-pm --save
In this example the ls command will be executed every seconds. This is not the goal of node-child-pm. This is just for exemple.
const ChildProcessManager = require('node-child-pm');
var pm = new ChildProcessManager({
command: 'ls',
args: ['-lh', '/usr'],
restartDelay: 1000,
cwd: './'
});
pm.start();
class : ChildProcessManager
- event : 'started'
- event : 'finished'
- event : 'message'
- pm.start()
- pm.stop()
- pm.send()
- pm.started
- pm.process
-
- options :
<Object>
options to pass to the- command | modulePath
<string>
(Required) : if command is used, the process will be started with child_process.spawn method If modulePath is used, the process will be started with child_process.fork method - args
<Array>
arguments used to spawn or fork the process - restartDelay
<int>
Default: 500 - delay before restarting a process in milliseconds
- command | modulePath
- options :
-
Emitted each time the process is spawned or forked
-
- code : exit code or error Emitted when process is finished
-
- message : the message transmitted by the process Emitted when the process send a message - only for forked process. (see child_process documentation)
-
Spawn the child process, you can pass args and options (see ChildProcessManager constructor)
-
Ends the child process
-
- message : the message to send to the process for other arguments (see child_process documentation)
-
return
<Boolean>
:true
if the process is running -
return
<child_process>
: The process attribute exposes the child process if you need it.