Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you debug a Node.js server running with Chrome/WebKit as the remote debugger?

If you have your Node running

node --debug server.js

This gives me a port number xxxx, should I use this port number when starting Chrome?

Do you remote debug into it from Google\ Chrome --remote-debugging-port=xxxx?

Or is the 9222 a magic port, as it is mentioned all over.

Am I on the right track, trying to start Chrome with --remote-debugger into the Node.js server.js

like image 209
Chris G. Avatar asked Sep 15 '12 18:09

Chris G.


People also ask

How do I debug Node JS in Chrome?

Using Google Chrome DevTools to Debug The next step is to head to Chrome, open a new tab, and enter the URL chrome://inspect/ . Click on “Open dedicated DevTools for Node” to start debugging the application. It will take a couple of seconds to view the source code in Chrome DevTools.

How do I enable remote debugging in Chrome?

Open the Developer Options screen on your Android. See Configure On-Device Developer Options. Select Enable USB Debugging.

How do I debug a remote server?

Using a browser, open the administration console of the remote application server. Expand the Servers node and click Application Servers. Click the name of the server to open the application server properties. Click Debugging Service.


2 Answers

The node-inspector / --debug are now replaced by inspector See update below

#now deprecated / see below for update

#install node-inspector
npm install -g node-inspector

#start node-inspector, listen on port 8080 (default)
node-inspector --web-port=8080

#in another terminal session/window:
#while node-inspector is running, start your project in debug mode 
node --debug myproject.js

Now you can browse to http://your_server:8080 for a full debug session of myproject.js

If your remote server is not accessible on the remote port because of firewalls or other reasons, you could create an ssh-tunnel to it from port 8080 on your local machine to 'localhost:8080' on the remote server:

ssh -L 8080:localhost:8080 username@remoteserver -N

and keep this running while you use http://localhost:8080 on your local machine to debug your remote nodejs session


Update august 2017

Start node in inspect mode:

node --inspect=0.0.0.0:9229 myproject.js

or if you want the debugger to break at the first line of myproject.js:

node --inspect-brk=0.0.0.0:9229 myproject.js

Then open the following URL in your chrome browser:

chrome://inspect

Click the 'Configure...' button and add the following target:

ip-or-name-of-server-running-node:9229

After you click the 'Done' button, you should see myproject.js under your remote targets. Click the inspect link to start debugging. Unfortunately, the inspect link does not work on Chrome 58 for Ubuntu. It works fine on Chrome 60 for Windows.

like image 154
anneb Avatar answered Oct 24 '22 06:10

anneb


Use node-inspector to remotely debug your node application from Chrome that you've started with the --debug option as you've shown.

like image 9
JohnnyHK Avatar answered Oct 24 '22 04:10

JohnnyHK