Reputation: 29369
I need to access the list of globally installed packages (those installed via npm install -g
) so I need to obtain the global prefix.
I already know about npm config get prefix
(see How to get the npm global path prefix) But, how can I code it on my node.js program?
Upvotes: 0
Views: 71
Reputation: 61
I believe you can use npm programatically, as such:
var npm = require('npm')
var prefix = npm.config.get('prefix');
More information here:
Upvotes: 0
Reputation: 33409
You can use child_process.exec()
to run the command:
var child_process = require('child_process');
child_process.exec('npm config get prefix', function(err, stdout){
var prefix = stdout.toString(); // stdout was a Buffer
console.log(prefix);
});
Upvotes: 1