I found how to install npm packages programmatically and the code works fine:
var npm = require("npm");
npm.load({
loaded: false
}, function (err) {
// catch errors
npm.commands.install(["my", "packages", "to", "install"], function (er, data) {
// log the error or data
});
npm.on("log", function (message) {
// log the progress of the installation
console.log(message);
});
});
If I want to install the first version of hello-world package, how can I do this in the NodeJS side, using npm module?
I know that I can use child process, but I want to choose the npm module solution.