Sitharth
Sitharth

Reputation: 137

Execute a command line with node js

How to execute a command line using 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?

Upvotes: 2

Views: 2066

Answers (1)

Fraction
Fraction

Reputation: 12954

Try to concatenate your variable with the command and add the path of your angular project to the cwd argument:

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) {
...

Upvotes: 1

Related Questions