Last active
December 11, 2015 17:58
-
-
Save m-allanson/4637797 to your computer and use it in GitHub Desktop.
Spawn a background process from grunt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.registerTask('spawn', 'Start app in the background', function () { | |
var fs = require('fs'), | |
spawn = require('child_process').spawn, | |
out = fs.openSync('./out.log', 'a'), | |
err = fs.openSync('./out.log', 'a'), | |
env = process.env; | |
env.NODE_ENV = 'testing'; | |
env.PORT = 7002; | |
grunt.log.writeln('Starting app in the background'); | |
grunt.log.writeln('stdout and stderr will be logged to out.log'); | |
var child = spawn('node', ['../src/server.js'], { | |
detached: true, | |
stdio: [ 'ignore', out, err ], | |
env: env | |
}); | |
child.unref(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment