New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

co-child-process

Package Overview
Dependencies
Maintainers
7
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-child-process

easily spawn a child process with co

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
7
Created
Source

Build Status

Co Child Process

Spawn a child process using co. Kind of like exec, except you can write to stdin and there aren't as many options like timeout or encoding.

Example

Minify a Javascript in a child process. Useful when the JS files are large and you don't want uglifyjs blocking the event loop.

var fs = require('fs')
var co = require('co')
var spawn = require('co-child-process')
// resolve the location of the binary
var uglifyjs = require.resolve('uglify-js/bin/uglifyjs')

co(function* () {
  var stream = fs.createReadStream(__filename)
  var minified = yield spawn(uglifyjs, [
    '-' // tells uglifyjs to check for `stdin`
  ]).pump(stream) // since you can't pipe into the generator
})()

API

var output = spawn(command, [args], [options])

A wrapper around child_process.spawn. The arguments are simply passed and are not touched.

Output is always a string, for now.

var output = spawn(args...).pump(stream)

Pump a stream into the child process' stdin. Kind of like .pipe() but in the opposite direction.

Must be called on the same tick.

var output = spawn(args...).end(body)

Write a buffer or string body to stdin.

var out = yield spawn(uglifyjs, ['-']).end('var a = 1;')

Must be called on the same tick.

FAQs

Package last updated on 02 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts