Skip to content

Instantly share code, notes, and snippets.

@crishushu
Last active August 29, 2015 14:02
Show Gist options
  • Save crishushu/18edf830c3e924ec52be to your computer and use it in GitHub Desktop.
Save crishushu/18edf830c3e924ec52be to your computer and use it in GitHub Desktop.
Gruntjs: Skeleton for node debugging
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
npmEnv: '', // path to node_modules folder
debugPort: '', // port to debug node
debugFile: '', // file to debug
concurrent: {
dev: {
tasks: ['nodemon', 'node-inspector'],
options: {
logConcurrentOutput: true,
limit: 4
}
}
},
'node-inspector': {
custom: {
options: {
'web-port': 1337,
'web-host': 'localhost',
'debug-port': '<%= debugPort %>',
'save-live-edit': true,
'no-preload': true,
'stack-trace-limit': 4,
'hidden': ['node_modules']
}
}
},
nodemon: {
dev: {
script: '<%= debugFile %>',
options: {
nodeArgs: ['--debug-brk=<%= debugPort %>'],
env: {
PORT: '5455'
},
callback: function(nodemon) {
nodemon.on('log', function(event) {
console.log(event.colour);
});
nodemon.on('config:update', function() {
setTimeout(function() {
var url = 'http://localhost:1337/debug?port=' + grunt.config.get('debugPort');
require('open')(url);
}, 1000);
});
nodemon.on('restart', function() {
// do whatever when node restarts
});
}
}
}
}
});
/**
* Other Requirements:
* open, node-inspector
*/
var NPM_ENV = grunt.config.get('npmEnv');
grunt.loadTasks(NPM_ENV + '/grunt-nodemon/tasks');
grunt.loadTasks(NPM_ENV + '/grunt-concurrent/tasks');
grunt.loadTasks(NPM_ENV + '/grunt-node-inspector/tasks');
grunt.registerTask('dev', ['concurrent']);
grunt.registerTask('default', ['concurrent']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment