简体   繁体   English

使用 node js 执行命令行

[英]Execute a command line with node js

How to execute a command line using nodejs.如何使用 nodejs 执行命令行。 I am trying to install a module in local by --save in my angular project using visual studio code editor but the script is not working.Anyone can find the mistake where i did?我正在尝试使用 Visual Studio 代码编辑器在我的 angular 项目中通过 --save 在本地安装一个模块,但脚本不起作用。任何人都可以找到我所做的错误?

Try to concatenate your variable with the command and add the path of your angular project to the cwd argument:尝试将您的变量与命令连接起来,并将您的 angular 项目的路径添加到cwd参数中:

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

Or using Template literals :或使用模板文字

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM