使用节点js执行命令行

时间:2019-08-01 11:45:40

标签: javascript node.js visual-studio-code

如何使用nodejs执行命令行。我正在尝试使用Visual Studio代码编辑器通过--save在本地项目中在本地安装模块,但是脚本无法正常工作。有人能找到我在哪里遇到的错误吗?

1 个答案:

答案 0 :(得分:1)

尝试使用命令连接变量,并将角度项目的路径添加到cwd参数:

child = exec("npm install --save" + module_ins,
{
  cwd: '/path_to_angular_project'
},
function (error, stdout, stderr) {
...

或使用Template literals

child = exec(`npm install --save ${module_ins}`,
{
  cwd: '/path_to_angular_project'
},
function (error, stdout, stderr) {
...