How to debug particular functionality in NodeBB
-
I'm new to NodeBB and node.js.
Before trying to debug NodeBB, set the NodeBB to working condition.
I use IntelliJ for development, so I created an empty "web static" to where NodeBB is located, then create a new "node.js" configuration. "JavaScript file" set to "app.js".
The NodeBB on my machine runs with MongDB.
After started NodeBB via the IDE, I can visit the forum, but there are some noticeable differences visually. Some buttons don't work neither, e.g., New Topic.
I also got the following error:
Failed to open socket on port 53023, waiting 1000 ms before retrying
I got some clue for the error, it might be related to "debugging a clustered app".
The whole message:
/usr/bin/node --debug-brk=57296 --nolazy app.js dev
debugger listening on port 57296
2/2 18:32 [19242] - info: NodeBB v0.6.1-dev Copyright (C) 2013-2014 NodeBB Inc.
2/2 18:32 [19242] - info: This program comes with ABSOLUTELY NO WARRANTY.
2/2 18:32 [19242] - info: This is free software, and you are welcome to redistribute it under certain conditions.
2/2 18:32 [19242] - info:
2/2 18:32 [19242] - info: Time: Mon Feb 02 2015 18:32:10 GMT+0000 (GMT)
2/2 18:32 [19242] - info: Initializing NodeBB v0.6.1-dev
2/2 18:32 [19242] - warn: [socket.io] Clustering detected, you are advised to configure Redis as a websocket store.
debugger listening on port 57296
2/2 18:32 [19242] - info: NodeBB is now listening on: 0.0.0.0:4567
Failed to open socket on port 57296, waiting 1000 ms before retrying
Failed to open socket on port 57296, waiting 1000 ms before retrying -
@madwyn I develop and debug NodeBB and plugins in Intellij.
Have you installed the Node.js plugin? If not, do so. It's available in the official Jetbrains repo.
Create a new Node.js application Run Configuration and set the javascript file to beapp.js
and optionally theNODE_ENV=development
environment variable.
At this point you can already debug NodeBB by just hitting the debug button on that configuration. However, it's incredibly slow. What I always do is add--debug
to the "Node parameters" field and create a new Node.js Remote Debugging configuration with the default settings.
Now you can just run NodeBB by just running the first configuration and if you want to do some debugging you start the remote debugging configuration and set some breakpoints.Screenshot of the configuration
You might even notice that I have this configuration in a plugin. It's quite convenient that I can launch NodeBB and start a debugging session right from the plugin project ;).
Be sure that you're running your database though. I usually start it from the terminal window in Intellij.
-
@Schamper Thank you very much!
I followed your instructions, now the NodeBB can run in IntelliJ and I can set break points.
However, in the console still prints similar error messages:
Failed to open socket on port 53969, waiting 1000 ms before retrying
Is this normal?
I have one more problem. It seems that one cannot log in, register account or create new topic in the debugging mode.
When I tried to log in, got
4/2 22:25 [1213] - error: /login Error: invalid csrf token at verifytoken (/Users/madwyn/projects/nodebb/node_modules/csurf/index.js:237:11) at csrf (/Users/madwyn/projects/nodebb/node_modules/csurf/index.js:100:7) at Layer.handle [as handle_request] (/Users/madwyn/projects/nodebb/node_modules/express/lib/router/layer.js:82:5) at next (/Users/madwyn/projects/nodebb/node_modules/express/lib/router/route.js:110:13) at Route.dispatch (/Users/madwyn/projects/nodebb/node_modules/express/lib/router/route.js:91:3) at Layer.handle [as handle_request] (/Users/madwyn/projects/nodebb/node_modules/express/lib/router/layer.js:82:5) at proto.handle.c (/Users/madwyn/projects/nodebb/node_modules/express/lib/router/index.js:267:22) at Function.proto.process_params (/Users/madwyn/projects/nodebb/node_modules/express/lib/router/index.js:321:12) at next (/Users/madwyn/projects/nodebb/node_modules/express/lib/router/index.js:261:10) at Function.proto.handle (/Users/madwyn/projects/nodebb/node_modules/express/lib/router/index.js:166:3)
Then the page shows
Forbidden
, from the code I can tell it is 403.Actually before your reply, I knew you from one of your plugins. I think that might be a good start for me to dig and eventually write something new.
Thanks!
-
-
@Schamper I have found the cause for the port problem, it's related to "debugging a clustered app" and it's an known issue with Node.js.
I resolved this issue by not using the Node.js from either yum or brew repositories, instead, I built it from source.
It is nice that the poll plugin will be updated.
I'll try to figure out the second problem. Meanwhile, wait @julian for some hints.
-
@madwyn said:
debugging a clustered app
It actually looks like this was fixed (or made much nicer, anyway) in 0.11:
https://strongloop.com/strongblog/whats-new-nodejs-v0-12-debugging-clusters/