Skip to content

Instantly share code, notes, and snippets.

@thanpolas
Last active December 12, 2015 06:09
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 thanpolas/4727303 to your computer and use it in GitHub Desktop.
Save thanpolas/4727303 to your computer and use it in GitHub Desktop.
Grunt Task for node
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-watch');
// Project configuration.
grunt.initConfig({
watch: {
node: {
files: ['lib/front/*.js'],
tasks: 'stopNode startNode'
}
}
});
var nodeChild;
grunt.registerTask('startNode', function() {
var sp = require('child_process').spawn;
nodeChild = sp('node', ['dep']);
console.log('Started node on pid: ' + nodeChild.pid);
nodeChild.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
nodeChild.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
nodeChild.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
});
grunt.registerTask('stopNode', function() {
nodeChild.kill(9);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment