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
Syntax: spawn(command, [args], [options])
var spawn = require('child_process').spawn;
var start = spawn('node', ['app.js'], {env: {NODE_ENV: 'production'}});
Or keep default ENV variables:
var spawn = require('child_process').spawn;
var productionEnv = process.env; // TODO should clone process.env like utils.extend
productionEnv.NODE_ENV = 'production';
var start = spawn('node', ['app.js'], {env: productionEnv});
My test:
app.js
console.log(process.env);
spawn.js
var spawn = require('child_process').spawn;
var start = spawn('node', ['app.js'], {env: {NODE_ENV: 'production'}});
start.stdout.pipe(process.stdout);
from terminal:
node spawn
output:
{ NODE_ENV: 'production' }