How to debug particular functionality in NodeBB



  • Hi,

    How to debug particular functionality in NodeBB such as "post a new topic", "Reply/comment".

    Any help would be greatly appreciated.
    Thanks!!!



  • 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


  • Admin

    Did you mean you wanted to switch to a different language? NodeBB supports many different languages, which you can take a look at (and request a new language for) here:



  • Hi @julian , would you please give me a hint of how to debug NodeBB using IntelliJ or similar IDE?


  • Plugin & Theme Dev

    @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 be app.js and optionally the NODE_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!


  • Plugin & Theme Dev

    @madwyn maybe try a different port?

    I'm not really familiar with the whole csrf fiasco, better get @julian in here ;)

    That poll plugin might not be te best plugin to start from, it's pretty dated. Updates are planned though.



  • @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.


  • Community Rep

    @madwyn said:

    debugging a clustered app

    It actually looks like this was fixed (or made much nicer, anyway) in 0.11:


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.