Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a basic node.js application (not http) on windows

I know how to debug http applications using node-inspector and iisnode. But can I use node-inspector to debug a non http node application, on windows?

I tried:

 node debug test.js 

It says:

debugger listening on port 5858 

But opening http://localhost:5858/ in Chrome does not do anything.


BTW: running node debug test.js does start the command-line debugger which works. But it's nothing like node-inspector.

like image 807
Sylvain Avatar asked Jul 11 '12 17:07

Sylvain


People also ask

Which of the following is a basic debugging tool for Node JS?

Atom Node Debugger is a simple debugging tool for both Node.

Which tools can be used to debug Node JS application?

js Debugger. Node. js provides built-in non-graphic debugging tool that can be used on all platforms. It provides different commands for debugging Node.

Which CLI option can you use to debug a Node?

A minimal CLI debugger is available with node inspect myscript. js . Several commercial and open source tools can also connect to the Node. js Inspector.


1 Answers

To use node-inspector, the right switch is node --debug not node debug

Here are the detailed steps:

  1. install node-inspector globally (npm install -g node-inspector)
  2. from a command-line window, run: node-inspector
  3. open Chrome and go to http://localhost:8080/debug?port=5858. You'll get the node-inspector UI but without any running app.
  4. from another command-line window, run your app with the --debug switch like this: node --debug test.js
  5. refresh the Chrome tab and voila!

A few interesting points:

  • If you kill your app and start it again, just refresh the node-inspector tab. It will keep all your breakpoints.
  • To break automatically on the first line start your app with node --debug-brk test.js
like image 120
Sylvain Avatar answered Sep 21 '22 05:09

Sylvain