Vadorequest
Vadorequest

Reputation: 17997

Use Webstorm debugger with node.js

I tried few weeks ago to make the webstorm debugger works, but it didn't. I'm trying again today, but I got the same result.

I'm following these instruction http://www.jetbrains.com/webstorm/webhelp/running-and-debugging-node-js.html#d93421e461

There are my configurations, I actually have three servers (use pomelo.js), one for the web, one as webservice, hosted on the game server and the game-server that basically is not reachable from http request directly. (use the webservice on the port 1500 to reach it)

https://docs.google.com/file/d/0ByzbHcAxmCyvQ1ZqZTFhREpZNGM https://docs.google.com/file/d/0ByzbHcAxmCyvV2JFWkwxTldJNFE https://docs.google.com/file/d/0ByzbHcAxmCyvZnVlYXNNSk4weHM https://docs.google.com/file/d/0ByzbHcAxmCyvN2o1VUhQR3cwX0U

When I click on Run:

"D:\Logiciels installés\nodejs\node.exe" --debug-brk=1337 web-server\app.js
debugger listening on port 1337

But I got nothing if I go on the webpage, just this error:

Code d'erreur : ERR_CONNECTION_ABORTED.

Now, if I run it in debug mode, two debug consoles opened: Debug Web:

"D:\Logiciels installés\nodejs\node.exe" --debug-brk=29855 --debug-brk=1337 web-server\app.js
debugger listening on port 1337
[ReferenceError: Buffer is not defined]
Grunt watcher starting...


*********** Controller Reader ***********


GET/POST/PUT/DELETE => /
GET/POST/PUT/DELETE => /chat
GET/POST/PUT/DELETE => /demo
GET/POST/PUT/DELETE => /login
GET/POST/PUT/DELETE => /game
GET/POST/PUT/DELETE => /subscribe
POST => /game/connect
GET => /mapEditor
POST => /mapEditor/:action
GET => /translate


********* Controller Reader End *********


Web server has started in development mode.
Please log on http://127.0.0.1:1337/index.html
grunt-cli: The grunt command line interface. (v0.1.11)

But if I go on the tab "Debugger" I got a "cannot connect".

The second debug console "Debug Web slave #1": I got nothing on the console but I got "connected to 127.0.0.1:1337" on the Debugger tab.

Sometimes when I try to reach the webpage I got something like this in the webpage:

Type: connect
V8-Version: 3.14.5.9
Protocol-Version: 1
Embedding-Host: node v0.10.24
Content-Length: 0

When I run the Debug mode, the Debug Web debugger tab try to connect to 127.0.0.30xxx, a random port around 30000, but fail and then display the "cannot connect".

Does someone understand what's going on? Because I don't... Thanks.

Edit:

Error: Failed to lookup view "..\views\game\layout.ejs"
    at Function.app.render (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\application.js:493:17)
    at ServerResponse.res.render (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\response.js:798:7)
    at C:\wamp\www\Ayolan\web-server\app\controllers\mainController.js:25:17
    at Function.app.render (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\application.js:495:14)
    at ServerResponse.res.render (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\response.js:798:7)
    at module.exports.index (C:\wamp\www\Ayolan\web-server\app\controllers\mainController.js:13:13)
    at callbacks (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\router\index.js:164:37)
    at param (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\router\index.js:138:11)
    at pass (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\router\index.js:145:5)
    at Router._dispatch (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\router\index.js:173:5)

Upvotes: 1

Views: 3948

Answers (2)

Sergey.Simonchik
Sergey.Simonchik

Reputation: 1041

Error: Failed to lookup view "..\views\game\layout.ejs"
   at Function.app.render (C:\wamp\www\Ayolan\web-server\node_modules\express\lib\application.js:493:17)
   ... 

Unlikely it was caused by environment variable, because parent environment variables are passed to an app by default . But I'd recommend you to make sure that parent environment variables are passed by clicking "Environment variables" on https://docs.google.com/file/d/0ByzbHcAxmCyvQ1ZqZTFhREpZNGM/edit ("Include parent environment variables" should be checked).

More likely "Working directory" is wrongly specified. Make sure it's the same as when you start your app from console.

Upvotes: 1

Sergey.Simonchik
Sergey.Simonchik

Reputation: 1041

When I click on Run:

   D:\Logiciels installés\nodejs\node.exe" --debug-brk=1337 web-server\app.js
   debugger listening on port 1337

But I got nothing if I go on the webpage, just this error:

   Code d'erreur : ERR_CONNECTION_ABORTED. 

That's expected, because your "Debug Web" run confuguration has "--debug-brk=1337" argument that makes Node.js app suspend right after startup. To resume it a Node.js remote debug session should be started with the same port.

Now, if I run it in debug mode, two debug consoles opened: Debug Web:

   "D:\Logiciels installés\nodejs\node.exe" --debug-brk=29855 --debug-brk=1337 web-server\app.js
   debugger listening on port 1337
   ... 

Note that the command line contains two duplicated parameters "--debug-brk=29855" and "--debug-brk=1337". The first parameter "--debug-brk=29855" is appended by WebStorm and the second one is taken from "Node parameters" field of "Debug Web" run configuration.

WebStorm assumes that the application would be ready for debugging on port 29855 and waits for the connection. But according to the output ("debugger listening on port 1337" line) the application's debugger is actually started on port 1337.

What happens next is that WebStorm sees that another debug port (1337) is opened and assumes that it's the debug port of a child node process. So WebStorm starts "Node.js Remote Debug" run configuration associated with 1337 port. That's why you see the second console ("Debug Web slave#1").

"Debug Web slave#1" console resumes application execution using port 1337. But "Debug Web" console is waiting for connection from port 29855 (that's why you see "cannot connect" there).

Just delete "--debug-brk=" in "Node parameters" field ("Debug Web" run configuration) and it should work as expected.

Hope that will help.

Upvotes: 1

Related Questions