you can use the debugger statement directly in your Node code to create breakpoints. When the Node runtime hits the debugger statement, it will pause execution if a debugger is attached.
function exampleFunction() {
const value = 42;
debugger; // Execution will pause here if a debugger is attached
console.log(value);
}
exampleFunction();
Start Your Application in Debug Mode using the --inspect or --inspect-brk flag when running your app.
node --inspect --5120 lib/app.js
If all goes as expected you will see the port to access to the breakpoints, example:
Debugger listening on ws://127.0.0.1:9229/65b96f6d-6202-49db-bbe8-63b706a580a2
Visit the port on your browser and open the Node DevTools. image.png54.1 KB
More info: https://nodejs.org/en/learn/getting-started/debugging