Simple handler for ChildProcess.spawn of Node.js
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.gitignore
.jshintrc
.npmignore
LICENSE
README.md
package.json

README.md

spawn-handler

Actual version published on NPM

Simple handler for ChildProcess.spawn of Node.js, it handles a child process spawned, then executes a callback when the process exits (optional).

spawn-handler has no external dependencies.

Quick start

Install

npm install spawn-handler

Usage

var spawn = require('spawn-handler');

spawn.run(command, [args], [options])

Shortcut of

var spawn = require('child_process').spawn;

spawn(command, [args], [options]);

Launches a new process (spawn) with the given command.

See the Node.js doc (spawn) for more details.

var ls = spawn.run('ls', ['-lh', '/usr']);

ls.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});

ls.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

ls.on('close', function (code) {
  console.log('child process exited with code ' + code);
});

spawn.handle(child, [done], [name])

Spawn handler.

var ls = spawn.handle(spawn.run('ls', ['./']), function(code) {
  console.log('Command exited with code ' + code);
}, 'List current directory');

ls.stdout.on('data', function(data) {
  console.log('files: ' + data);
});

ls.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

Testing

spawn-handler is tested with Unit.js and Mocha. Unit.js is a powerful and intuitive unit testing framework for javascript.

License

MIT (c) 2013, Nicolas Tallefourtane.

Author

Nicolas Tallefourtane - Nicolab.net
Nicolas Talle
Make a donation via Paypal