Be the first user to complete this post
|
Add to List |
Debugging nodejs applications using node-inspector and Chrome Dev Tools
Basic Setup
First install node inspector globally
sudo npm install -g node-inspector
node-debug app.js
http://localhost:8080/debug?port=5858
and debug your applications. However, we want to take this a little further and convert it into a configurable npm run script. Lets see how we can do that.
Advanced setup
The aim of this setup is to run your node server in debug mode as a grunt task what whose configuration can be specified in a file instead of doing it on the command line.
grunt debug --file=app.js
npm install grunt-run --save-dev
module.exports = {
'node-inspector': {
cmd: 'node-debug',
args: []
}
}
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json')
});
// Read the config for the 'run' task that can run any command
var runConfigs = require('./grunt/run.js');
if(!runConfigs['node-inspector'].args){
runConfigs['node-inspector'].args = [];
}
// Prepend the file name to the command line arguments array
// for the node-inspector task
runConfigs['node-inspector'].args.unshift(grunt.option('file'));
grunt.config( 'jshint', require('./grunt/jshint.js') );
grunt.config( 'run', runConfigs );
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-run');
grunt.registerTask('default', ['jshint']);
grunt.registerTask('debug', ['run:node-inspector']);
};
scripts:{
// other scripts
// ...
"debug": "grunt debug --file=app.js"
}
Also Read:
- Resolved - Error: listen eaccess using nodejs and pm2
- Understanding expressjs middleware with a visual example
- Use node in es6 syntax with babel transpiling
- How to publish a package on npm