Use NPM commands programmatically
npm install npm-programmaticnpm-programmatic is a library that allows you to access npm commands programmatically from javascript
`` `
npm.install(packages, opts).then(function)
| Name | Type | Value |
| ------------- |:-------------:| -----:|
| packages | Array | packages to be installed |
| opts | Object | save:true/false; global:true/false; cwd:string; saveDev:true/false; noOptional:true/false; legacyBundling: true/false; output:true/false|
var npm = require('npm-programmatic');
npm.install(['left-pad'], {
cwd:'/path/to/my/project',
save:true
})
.then(function(){
console.log("SUCCESS!!!");
})
.catch(function(){
console.log("Unable to install package");
});
`Unistallation of Packages
`
npm.uninstall(packages, opts).then(function)
`
| Name | Type | Value |
| ------------- |:-------------:| -----:|
| packages | Array | packages to be uninstalled |
| opts | Object | save:true/false; global:true/false; cwd:string; saveDev:true/false; output:true/false|$3
`
var npm = require('npm-programmatic');
npm.uninstall(['left-pad'], {
cwd:'/path/to/my/project',
save:true
})
.then(function(){
console.log("SUCCESS!!!");
})
.catch(function(){
console.log("Unable to uninstall package");
});
`
List Installed Packages
`
npm.list(path).then(function)
`
| Name | Type | Value |
| ------------- |:-------------:| -----:|
| path | String | path at which to look |$3
`
var npm = require('npm-programmatic');
npm.list('/path/to/project')
.then(function(arrayOfPackages){
console.log(arrayOfPackages);
})
.catch(function(){
console.log("Unable to uninstall package");
});
`Tests
install mocha and dev dependencies. Then run
` npm test ``