How to Debug Node.js with the Inspector and Chrome DevTools
Node.js has a built-in inspector that connects to Chrome DevTools, giving you real breakpoints, step-through execution and live variable inspection — a huge upgrade over scattering console.log everywhere. Once you use it, you will not go back.
Starting the inspector
Launch your app with the inspect flag:
node --inspect app.js
To pause before your code runs (useful for debugging startup), use --inspect-brk instead. Node prints a URL and a WebSocket endpoint for the debugger.
Connecting Chrome DevTools
- Open Chrome and go to
chrome://inspect. - Under "Remote Target", click inspect on your Node process.
- DevTools opens, connected to your running app.
Many editors (like VS Code) also attach to the inspector directly, so you can debug without leaving your editor.
What you can do
- Set breakpoints and pause execution exactly where you want.
- Step over, into and out of functions line by line.
- Inspect variables and the call stack at any point.
- Run code in the console against the paused state.
- Capture profiles and heap snapshots — see analyzing snapshots and profiles.
Debugging on a remote server
You can debug an app on a VPS by connecting over an SSH tunnel to the inspector port — never expose the inspector port publicly, as it grants full control. Set up secure access with SSH keys and tunnel the port locally.
Frequently asked questions
Is it safe to run --inspect in production?
Be cautious — the inspector allows full code execution, so never expose its port to the internet. If you must debug in production, bind it locally and reach it only through a secure SSH tunnel.
--inspect or --inspect-brk?
Use --inspect for a running app, and --inspect-brk when you need to debug startup code, since it pauses on the first line until you connect and resume.
Can I use this with VS Code?
Yes — VS Code has built-in Node debugging that attaches to the inspector, letting you set breakpoints in your editor. It is often the smoothest workflow.
Was this article helpful?