Debugging Node.js Apps

Many tools and libraries are available to help you debug your Node.js apps. Some of these are listed below.

To connect manually rather than with a tool, pass the --inspect flag and connect to the printed URL.

If a process was started without --inspect, signal it with SIGUSR1 to activate the debugger and print the connection URL.


Inspector Tools & Clients

These commercial and open source tools make debugging Node.js apps easier.

node-inspect

  • A CLI debugger developed at https://github.com/nodejs/node-inspect.
  • Bundled with Node and invoked with node inspect myscript.js.
  • Can also be installed independently with npm install -g node-inspect and invoked with node-inspect myscript.js.

Chrome DevTools 55+

VS Code 1.10+

  • In the Debug panel, click the settings icon to open .vscode/launch.json. Select "Node.js" for initial setup.

Visual Studio

JetBrains WebStorm 2017.1+ and other JetBrains IDEs

  • Create a new Node.js debug configuration and hit Debug.

chrome-remote-interface

  • Library to ease connections to Inspector Protocol endpoints.

Command-line options

The following table lists the impact of various runtime flags on debugging:

FlagMeaning
--inspect
  • Enable inspector agent
  • Listen on default port (9229)
--inspect=port
  • Enable inspector agent
  • Listen on port port
--inspect-brk
  • Enable inspector agent
  • Listen on default port (9229)
  • Break before user code starts
--inspect-brk=port
  • Enable inspector agent
  • Listen on port port
  • Break before user code starts
node inspect script.js
  • Spawn child process to run user's script under --inspect flag; and use main process to run CLI debugger.
Scroll to top