【发布时间】:2020-06-04 18:09:05
【问题描述】:
在 package.json 文件中,我在 scripts 对象中有这样一行:
"scripts": {
// some commands..
"runpackage": "someNpmPackage -args"
}
这个someNpmPackage 是我的node_modules 中的一个包,但不在命令行中。 (即我可以在终端中运行命令)。
这很好用。但是,我希望能够在脚本中做到:"runPackage": "node scripts/runPackage.js"
我尝试类似的东西
var exec = require('child_process').exec;
exec('someNpmPackage -args', function (err) {
if (err) {
console.log(err.message);
process.exit();
}
console.log('success');
});
但我得到的只是/bin/sh: someNpmPackage: command not found。
如何让exec 函数知道这个包?
【问题讨论】:
标签: node.js node-modules