My unbuild node.js project is on a file server and I want to execute the npm script "build" which should build the application. But I can't find a way to call this command through code. Does anyone know if this should be possible? When I try to search for a result I keep finding tutorials on how npm script work, which is not what I want to know. Is it possble to run an npm script (command?) from code?
You can use child_process.exec
to execute a script:
var exec = require('child_process').exec;
var cmd = exec("npm build", function(err, stdout, stderr) {
if (err) {
// handle error
}
console.log(stdout);
});
dir.on('exit', function (code) {
// return value from "npm build"
});
you can use concurrently npm package, it allow managing your npm scripts and provides API to call npm-scripts from inside your Node app project, check programmatic-usage section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With