How to debug Node.js code?
I'm trying to debug the simple "Getting Started" Node.js code found here: https://nodejs.org/en/docs/guides/getting-started-guide/
This is the debugging configuration I have set:

I have set breakpoints to every line and I have read the instructions here: https://www.jetbrains.com/help/webstorm/running-and-debugging-node-js.html, but after I run the Node.js code under debugging mode in WebStorm and open the URL http://localhost:3000 in browser, the browser complains "This site can’t be reached". This is the WebStorm output:
"C:\Program Files\nodejs\node.exe" --inspect-brk=55028
Debugger listening on ws://127.0.0.1:55028/3facca49-6de9-4303-82bb-24b3a85d20a8
For help see https://nodejs.org/en/docs/inspector
>
If I changed the port in the URL to 55028, the browser says: "WebSockets request was expected". I have no idea what it means. What do I do to debug this simplest code in WebStorm? What did I miss? The version of WebStorm I am using is the latest 2017.3.1 and I am working on Windows 7 64 bit. Thanks for your help.
PS: the Node.js remote debugging in WebStorm works.
Please sign in to leave a comment.
Debugging this code works fine for me.
Some questions:
- why didn't you pass the file to Node.js? JavaScript file: field in run configuration is empty
- what lines did you set breakpoints at? Were breakpoints hit? May be, the execution is suspended on breakpoint, thus the server doesn't start? Did you enable exceptions breakpoints?
>If I changed the port in the URL to 55028
what for?
Thank you very much, Elena. I missed the "Javascript file" field. After I typed the file name app.js into it, everything works as expected now. Thank you for your help!