What is the correct syntax to spawn a process in Node.js?


I'm trying to follow along with


In an effort to do

./node_modules/.bin/mocha --reporter json -u tdd

I have tried

var mocha    = spawn('./node_modules/.bin/mocha', ['--reporter json -u tdd']);

But I get the following error

error: unknown option `--reporter json -u tdd'

What am I doing wrong?

Problem courtesy of: deltanovember


Looking quickly at the reference URL you provided, it seems that your bracketed arguments need to be separate:

var mocha    = spawn('./node_modules/.bin/mocha', ['--reporter','json','-u','tdd']);
Solution courtesy of: OrionRogue


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.