Skip to content

Instantly share code, notes, and snippets.

@etiktin
Created November 8, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etiktin/455b09cb426477a35cc3 to your computer and use it in GitHub Desktop.
Save etiktin/455b09cb426477a35cc3 to your computer and use it in GitHub Desktop.
Using npm API to remove dev dependencies from your node_modules folder (equivalent of `npm prune --production`)
var npm = require('npm');
var cb = funtion (error) {
if (error) {
console.log('Failed to remove devDependencies');
} else {
console.log('devDependencies removed from node_modules');
}
};
// Before calling a command we need to setup it's configuration
npm.load({
production: true, // Will make prune remove devDependencies
prefix: PATH_TO_NODE_MODULES_PARENT // Optional. If not provided, remove node_modules from the current app
},
function (error) {
if (error) {
cb(error);
return;
}
// The configuration is ready so we call the prune command
npm.commands.prune(cb);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment