Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials Node.js Debugging with Node
Node.js Intermediate FREE

Debugging with Node

Lesson 2 of 17 Intermediate Interactive

Node.js has built-in debugging tools and supports the inspector protocol.

Syntax

NODEJS
node --inspect app.js
node --inspect-brk app.js

debugger; // breakpoints in code
Node.js Debugging
NODE
const debug = require("debug")("app:server");

function processData(items) {
    debug("Processing %d items", items.length);
    const result = items.map(item => {
        debug("Processing item: %o", item);
        return item * 2;
    });
    debug("Result: %o", result);
    return result;
}

processData([1, 2, 3, 4, 5]);

// Console methods
console.log("Log message");
console.warn("Warning");
console.error("Error");
console.time("timer");
console.timeEnd("timer");