Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 686
cocoseis Avatar asked Apr 18 '26 05:04

cocoseis


1 Answers

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.

like image 138
Julian Avatar answered Apr 19 '26 17:04

Julian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!