1.2.1 • Published 8 years ago

spawnsync-npm-install v1.2.1

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

spawnsync-npm-install

stable

Programmatically install/uninstall npm dependencies by spawning a npm child process.

var install = require('spawnsync-npm-install')
console.log("install start");
install(['through2', 'quote-stream'], { saveDev: true }, function(err) {
  if (err)
    console.error("Could not install:\n" + err.message)
  else
    console.log("Installed.")
});
console.log("install end");

Or, to preserve log output and colors:

install('tape', { stdio: 'inherit' })

PRs welcome.

Usage

NPM

spawn = require('spawnsync-npm-install')

proc = spawn.install(dependencies, [opt], [cb])

Spawns an npm install using the given dependencies (string or array of strings). You can pass opt to the command, which will convert camel case to dash-case for the CLI arguments. The last parameter cb is the callback which is passed (err) on failure, or null otherwise.

You can specify a command for options to use instead of the default npm (e.g. for specialized analytics or other hooks).

Also accepts some options for the child process:

  • env environment variables
  • stdio the standard err/out
  • cwd the current working directory

Returns the child process.

Examples:

var install = require('spawn-npm-install')
install('tape', { saveDev: true }, done)

install(['zalgo', 'img'], function(err) {
  if (err) 
    console.error(err.message)
})

License

MIT, see LICENSE.md for details.