NPM.installPackage()

Install a package from the NPM registry to the node_modules folder of a local project.

Usage

Hover over inputs/exits for more info.

var NPM = require('machinepack-npm');


// Install a package from the NPM registry to the node_modules folder of a local project.

NPM.installPackage({

name: 'express',

version: '~1.0.0',

dir: '/Users/mikermcneil/dogfood-promo-site',

save: false,

saveDev: false,

saveExact: false,

prefix: './path-to-project',

loglevel: 'warn',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// Provided semver range is invalid. See https://docs.npmjs.com/misc/semver for more information.

invalidSemVer: function () {

 

},

// OK.

success: function () {

 

},

});

Inputs

name required

The name of the NPM package to install.

'express'
version

A version string (or semver range) of the NPM package to install.

'~1.0.0'
dir

The local path where the package should be installed as a dependency.

'/Users/mikermcneil/dogfood-promo-site'
save

If set, the installed package will be saved to the package.json file as a dependency.

false
saveDev

If set, the installed package will be saved to the package.json file as a development-only dependency.

false
saveExact

If set, the installed package will be saved to the package.json file as an exact version, rather than a semver range.

false
prefix

An optional path prefix which affects the root path in which this NPM package gets installed.

'./path-to-project'
loglevel

If set, NPM will write logs to the console at the specified log level.

'warn'

Exits

error

An unexpected error occurred.

invalidSemVer

Provided semver range is invalid. See https://docs.npmjs.com/misc/semver for more information.

success

OK.