Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

by Gergely Nemeth @

RisingStack

3 Ways to
Debug
Node.js

Use this Cheat-Sheet to


debug Node.js easily
Method 1: The debug module
▢ To check whether a module is using the debug module, take a look at the
package.json file's dependency section.

▢ Set the DEBUG environment variable when starting your app. You can
also use the * character to wildcard names.

▢ The following line will print all the express related logs to the standard
output > DEBUG=express* node app.js

Method 2: The Built-in Node.js Debugger


▢ Node.js includes a full-featured built-in debugging client. To start the
built-in debugger you have to start your application this way: "node
debug app.js"

▢ To navigate this interface, use the following commands:


c => continue with code execution
n => execute this line and go to next line
s => step into this function
o => finish function execution and step out
repl => allows code to be evaluated remotely

Method 3: The Chrome Debugger


▢ Install node-inspector first: "npm install -g node-inspector"

▢ Start debugging your app by starting this way: "node-debug index.js --


debug-brk " (the --debug-brk pauses the execution on the first line)

▢ It will open up the Chrome Dev tools and you can start to debug your app
JOIN FOR
MORE FREE
RESOURCES

Watch the 9-minute screencast to get


the most out of this cheat sheet

JOIN NOW

You might also like