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:
- Configure The 'script' tag In package.json To Run Multiple Commands
- Accessing the request body and session in nodejs using express
- Configuring jshint as a pre-commit hook for your nodejs applications
- Setup passportjs for local authentication and authorization using expressjs