cocoseis
cocoseis

Reputation: 1463

Angular-Cli from NodeJS

Building my project using Angular-Cli works when I use it directly from my terminal window like this:

$ ng build

Now I'd like to run it from nodejs using spawn. However,

const spawn = require('child_process').spawn;
const bld = spawn("ng build");

throws:

child process has an error with code Error: spawn ng build ENOENT
child process exited with code -2

Why is this happening? (I am running everything from inside the same folder.)

Upvotes: 3

Views: 640

Answers (1)

Julian
Julian

Reputation: 2822

Spawn doesn't behave like a command line.

You send the command and args separately like:

spawn('ng', ['build'])

In your case it tried to do ng\ build and can not find that file.

Upvotes: 3

Related Questions