70

I'm trying to debug my nodejs app using node-inspector. But Google Chrome doesn't show the code.

I'm using the following,

Node.js : v0.10.26

Express : 4.0.0

Node Inspector : v0.7.3

Google Chrome version : 34.0.1847.131

This is what I'm doing to start the debugger..

$ node-inspector
Node Inspector v0.7.3
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.

In another console,

$ node --debug app.js 
debugger listening on port 5858
$

Then started Google Chrome and went to

http://127.0.0.1:8080/debug?port=5858

It opens up node-inspector but without any code..all windows are empty.

Noticed that I'm not getting 'Express server listening on port 3000'

Tried all as per node-inspector fails to connect to node but no luck

Couldn't work out what I'm missing. Would be great of you have any suggestions..so I can debug my Node.js apps in Google Chrome.

asked Apr 28, 2014 at 12:19
2
  • 3
    1. Try to run node-inspector with --no-preload option. Commented Apr 28, 2014 at 13:07
  • 1
    2. Check Chrome's DevTools console - are there any errors? Commented Apr 28, 2014 at 13:07

6 Answers 6

122

Try to run node --debug-brk app.js instead of just --debug. Your application may not be pausing before node inspector hooks into the node process. Using --debug-brk will force node to break on the first line of your app and wait for a debugger to attach to the process. Loading the node-inspector web interface is what causes node-inspector to attach to your node process; that's why you include the node debug port in the query string (localhost:8080/debug?port=5858). You're telling node-inspector what port it should reach out and attach to.

Here's an animated gif I put together showing a complete install and run of node-inspector.

In the gif I use the --debug flag because I'm not debugging any code that runs right at startup. I'm debugging inside a request handler, which only fires when the page is requested. Thus, refreshing the page causes node-inspector to break on that line.

I also put together a 15 minute YouTube tutorial a while ago.

http://youtu.be/03qGA-GJXjI

starball
59k52 gold badges310 silver badges1k bronze badges
answered Apr 28, 2014 at 16:04
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Alex, I did check your youtube video before..very informative thanks. --debug-brk did the trick for me..however..when I put a breakpoint in one of my routes. In my case, I'm experimenting with cheerio + request to scrape a website. I've created a route, lets say scrape.js Im hoping to debug this file..but its not hitting the breakpoint..am I missing something?
I'm not sure. It's hard to know without a code sample. Can you paste all the code that runs up to the point where that route is declared in a gist along with the URL you're navigating to to trigger the request handler?
@AlexFord: How did you manage to create this gif? I think its really cool & can be very helpful
@SharpCoder I used Camtasia to record a video. In their advanced export options you can choose animated gif.
@SutikshanDubey refer to this answer. When you get to step 3 make sure you are using the node-inspector command and not the node-debug command. The node-debug command both runs your script and starts up the node-inspector server. You just want to start the server, not start your script. Then you can start your script separately using the --debug-brk flag.
|
22

node-inspector by default tries to pre-load all the code before initiating the debug window. I have had instances, node-inspector just hangs for ever because of this pre-loading. Luckily the newer versions have an option to stop the pre-load thereby making the inspector load faster.

Try node-inspector --no-preload

answered Apr 15, 2015 at 22:53

1 Comment

Very helpful! I too have had this stupid hanging problem when I'd rather just hit breakpoints right away. Thanks for the tip!
6

Standard remote debugging is broken entirely in node 6.5. It's replaced however by a new internal node feature

$ node --inspect --debug-brk build/server/server.js
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
 chrome-devtools://devtools/remote/serve_file/@62cd277117e6f8ec53e31b1be58290a6f7ab42ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
Debugger attached.

See here - http://arveknudsen.com/?p=346%3Fpage_id%3D346&print=pdf - for more info

lumio
7,6054 gold badges42 silver badges60 bronze badges
answered Sep 15, 2016 at 14:33

2 Comments

You just saved my day! No need for node-inspector anymore.
hmm, in my case it's giving me a URL starting with "ws://" ... the machine is a headless server, so I passed the host:port option, yet I still can't open the "ws://" URL in my local instance of Chrome
1

--debug-brk is now deprecated

try node --inspect-brk <your starting file name> and then go to chrome and type url chrome://inspect and click on Open dedicated DevTools for Node, the debugger will start, no need of node-inspector

answered Jul 13, 2018 at 9:29

Comments

0

enter image description here

On the left of Node Inspector, "Sources" tab, there is "a box with a triangle in it" - highlighting says "Show Navigator". (See it in the picture above). Open that to find the files you want to debug, and put a break point on code that has yet to run.

Also note, if you want to debug code that runs on starting node, you'll need to use the --debug-brk option when starting. Then, in Node Inspector, you you'll have to kick off the app (F8 to run all). You'll need this option if you want to debug all the initialization code, like starting a web browser.

answered Apr 28, 2014 at 16:02

1 Comment

Thanks Clay, --debug-brk seem to have worked..it did't work initially though..but after trying few times..it did..
0

node-debug --no-preload app.js

This what's working for me. According to this:

My script runs too fast to attach the debugger.

The debugged process must be started with --debug-brk, this way the script is paused on the first line.

Note: node-debug adds this option for you by default.

halfer
20.2k19 gold badges110 silver badges207 bronze badges
answered Nov 28, 2017 at 8:16

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.