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

Problem

I'm trying to follow along with

http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

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

Solution

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

Discussion

There is currently no discussion for this recipe.

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