Skip to content

Instantly share code, notes, and snippets.

@m-allanson
Last active December 11, 2015 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-allanson/4637797 to your computer and use it in GitHub Desktop.
Save m-allanson/4637797 to your computer and use it in GitHub Desktop.
Spawn a background process from grunt
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