I\'m currently trying to run process using spawn
. What I am trying to run from shell is the following;
NODE_ENV=production node app/app.js
Your usage of spawn is not correct:
spawn( command, args, options )
:Launches a new process with the given command, with command line arguments in args. If omitted, args defaults to an empty Array.
The third argument is used to specify additional options, which defaults to:
{ cwd: undefined, env: process.env }
Use env to specify environment variables that will be visible to the new process, the default is process.env.
So the env variable NODE_ENV
should be provided on the options argument:
// ES6 Object spread eases extending process.env
spawn( 'node', ['app.js'], { env: { ...process.env, NODE_ENV: 'test' } }})
See also How do I debug "Error: spawn ENOENT" on node.js?