i wondering correct way add "execargs" node process -
we have:
const cp = require('child_process'); const n = cp.spawn('node', ['some-file.js'], {});
but if want add execarg so:
const n = cp.spawn('node --harmony', ['some-file.js'], {});
i don't think right way it, , docs don't seem demonstrate this?
is correct way?
const n = cp.spawn('node', ['--harmony','some-file.js'], {});
according docs child_process.spawn()
states args array of string arguments passed in second argument.
the child_process.spawn() method spawns new process using given command, command line arguments in args. if omitted, args defaults empty array.
a third argument may used specify additional options, these defaults:
{ cwd: undefined, env: process.env }
example of running ls -lh /usr, capturing stdout, stderr, , exit code:
const spawn = require('child_process').spawn; const ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); }); ls.stderr.on('data', (data) => { console.log(`stderr: ${data}`); }); ls.on('close', (code) => { console.log(`child process exited code ${code}`); });
based on above pulled child_process docs, below correct.
const n = cp.spawn('node', ['--harmony','some-file.js']);