I wish to run commands like NODE_ENV=production node server
or cd ~/app/cms; npm test
with NodeJs spawn
First can be achieved with
process.env.NODE_ENV = 'production'
start = spawn 'node', ['server'], process.env
But how can I achieve the second?
Updated: In case someone have similar problem, here is my example in coffeescript:
testCode = ->
testCore = spawn 'npm', ['test']
testCore.stderr.on 'data', (data) -> console.log() process.stderr.write data.toString()
testCore.stdout.on 'data', (data) -> print data.toString()
testCore.on 'exit', ->
path = require 'path'
process.chdir path.join(__dirname, "app", "linkParser")
testModule = spawn 'npm', ['test']
testModule.stderr.on 'data', (data) -> process.stderr.write data.toString()
testModule.stdout.on 'data', (data) -> print data.toString()