Javascript Debugging

This is gonna be a quicky on how to debug your standalone javascript. I assume you already know how to debug javascript using the browser’s inspector and are familiar with break points, scope vars, control flow, and everything else you can do in that inspector debugger.

The task here is to debug a standalone javascript program (not running in a browser).

Say you have a helloworld.js

You can run it like so

node helloworld.js

You can also debug it with like so

node --inspect-brk helloworld.js

The –inspect-brk option will set a breakpoint on the 1st line and wait for you to attach the debugger. Otherwise your program may run through thousands of lines of code before you’re quick enough to attach the debugger and stop it. This option is available in node version 7.x+. I didn’t have it in 7.2 though, so I upgraded to 8.9.4 which had it.

Then, open your chrome browser to about:inspect. You should see something like this

Screen Shot 2018-01-11 at 1.54.11 PM

Click on “Open dedicated DevTools for Node” and this will open the inspector debugger that you’re used to

Tagged ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: