childminder
v1.1.2
Published
Promise based child process manager for development
Downloads
8
Maintainers
Readme
childminder
childminder
is a promise based child process manager for development.
import { Childminder } from 'childminder';
const cm = new Childminder();
const child = cm.create('echo', ['Hello, world'], {
prefix: 'greeting',
prefixColor: 12,
});
child.restart();
Features
- Colorful console prefix
- Preserve child process console message color
- Handle multiple processes
Motivation
nodemon is a useful tool in node.js server programming. It watches file changes and restarts node.js process automatically. If we use transpilers like Babel, CoffeeScript or TypeScript, however, process should not restart when file changes but when transpilation is completed. Maybe in this case, we should monitor events from transpiler and reload process manually.
childminder
is yet another tool for development like nodemon, but does not watch file changes. When using childminder
, you should call childminder
process restart function manually, which looks cumbersome but indeed is a clear way.
API
Class: Childminder
Process manager that contains multiple Child instances.
Childminder#create(command[, args][, options]) => Child
Create Child
instance.
command
String The command to runargs
Array List of string argumentsoptions
Objectcwd
String Current working directory of the child processenv
Object Environment key-value pairsprefix
Stringstdout
message prefixprefixColor
Number Prefix xTerm colorsstdout
stream.Writable Child's stdout stream (Default:process.stdout
)lazy
Boolean If true,Child
process does not start running when created (Default:false
)
- returns
Child
instance.
Class: Child
Thin wrapper of node.js ChildProcess object, which supports restart. Child
instance is created by Childminder#create
method.
Child#startOrRestart() => Promise<void>
Starts or restarts child process. Returned promise is resolved when the previous process exits and new process gets started.
Child#restart() => Promise<void>
Restarts running child process. Returned promise is resolved when the previous process exits and new process gets started.
Child#waitForExit() => Promise<void>
Wait for child process to terminate. Returned promise is resolved when the process exits.
Child#isRunning() => boolean
Returns if the child process is running.
Child#kill(signal = 'SIGHUP') => Promise<void>
Kill child process and wait for it to terminate. Returned promise is resolved when the process exits.
License
MIT