Grunt Node Inspector is a Grunt plugin that integrates node-inspector into Grunt workflows for debugging Node.js applications. It provides a convenient way to configure and run node-inspector as a Grunt task with extensive customization options including port configuration, SSL support, debugging settings, and UI visibility controls.
npm install grunt-node-inspector --save-devAfter installation, load the plugin in your Gruntfile:
grunt.loadNpmTasks('grunt-node-inspector');The minimal usage of node-inspector runs with no options:
module.exports = function(grunt) {
grunt.initConfig({
'node-inspector': {
dev: {}
}
});
grunt.loadNpmTasks('grunt-node-inspector');
};When this task is run with grunt node-inspector:dev, node-inspector will be available at 0.0.0.0:8080.
Configure the node-inspector Grunt task with various options for debugging Node.js applications.
/**
* Grunt task configuration for node-inspector
*/
'node-inspector': {
[target: string]: {
options?: NodeInspectorOptions;
};
}
interface NodeInspectorOptions {
/** Port to connect to the debugging app (default: 5858) */
'debug-port'?: number;
/** Host to listen on (default: '0.0.0.0') */
'web-host'?: string;
/** Port to host the inspector (default: 8080) */
'web-port'?: number;
/** Save live edit changes to disk (default: false) */
'save-live-edit'?: boolean;
/** Enables preloading *.js files. Set to false to speed up startup (default: true) */
'preload'?: boolean;
/** Array of files to hide from the UI (breakpoints in these files will be ignored) */
'hidden'?: string[];
/** Number of stack frames to show on a breakpoint (default: 50) */
'stack-trace-limit'?: number;
/** File containing a valid SSL key for HTTPS inspector */
'ssl-key'?: string;
/** File containing a valid SSL certificate for HTTPS inspector */
'ssl-cert'?: string;
}Basic Configuration Example:
module.exports = function(grunt) {
grunt.initConfig({
'node-inspector': {
dev: {
options: {
'web-port': 1337,
'debug-port': 5857
}
}
}
});
grunt.loadNpmTasks('grunt-node-inspector');
};Advanced Configuration Example:
module.exports = function(grunt) {
grunt.initConfig({
'node-inspector': {
custom: {
options: {
'web-host': 'localhost',
'web-port': 1337,
'debug-port': 5857,
'save-live-edit': true,
'preload': false,
'hidden': ['node_modules'],
'stack-trace-limit': 4
}
}
}
});
grunt.loadNpmTasks('grunt-node-inspector');
};HTTPS Configuration Example:
module.exports = function(grunt) {
grunt.initConfig({
'node-inspector': {
https: {
options: {
'web-host': 'localhost',
'web-port': 1337,
'debug-port': 5857,
'ssl-key': './ssl/key.pem',
'ssl-cert': './ssl/cert.pem'
}
}
}
});
grunt.loadNpmTasks('grunt-node-inspector');
};The plugin exports a function that registers the node-inspector task with Grunt.
/**
* Plugin entry point - registers the node-inspector multi-task
* @param grunt - The Grunt object
*/
module.exports = function(grunt) {
// Registers 'node-inspector' multi-task with Grunt
};Execute the node-inspector task with Grunt CLI commands.
# Run specific target
grunt node-inspector:dev
grunt node-inspector:custom
# Run default target (if configured)
grunt node-inspectorPort to connect to the debugging app.
number5858Host to listen on for the web interface.
string'0.0.0.0'Port to host the inspector web interface.
number8080Save live edit changes to disk.
booleanfalseEnables preloading *.js files.
booleantruefalse to speed up startup by not preloading JavaScript filesArray of files to hide from the UI.
string[][]node_modulesNumber of stack frames to show on a breakpoint.
number50SSL key file for HTTPS inspector.
string''SSL certificate file for HTTPS inspector.
string''The plugin will terminate the Grunt process if node-inspector fails to start:
When errors occur, check:
web-port and debug-port)