简体   繁体   中英

Node.js Debugging flow

I'd like to debug node.js like rails. I've tried several ways:

  1. Webstorm debug – in this case I need to click "rerun debug" each time after code changed
  2. Nodemon with chrome remote debugger – in this case I need to reconnect to debugger each time after code reloaded by nodemon
  3. pry.js – here I need to type "eval(pry.it)" – and have no option to make it simpler like "debug" or pry()

So what's the best option to debug node apps like byebug for rails?

Upgrade:

Thx to @AbhinavD I've managed to do it in VSCode: First you need to edit app/.vscode/launch.js javascript { "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "Node: Nodemon", "processId": "${command:PickProcess}", "restart": true, "protocol": "inspector", }, ] } So now nodemon restarts server after changes and VSCode reconnect to debugger automatically.

See video https://vimeo.com/267975071

Is anybody able to do it in WebStorm?

To answer your question: There is no way . Unfortunately, with Node.js, you always have to restart the debugging session when you change your code 😕.

I've recently written an article about debugging both JavaScript and TypeScript using different tools, if you're interested, but there's nothing like live debugging.

Now with the upgrade works just fine. [23/09/2018]

For configuration you need to have the Webstorm 2018. 2 and follow the steps below:

Webstorm运行/调试配置

and ALSO include the option to "Attach to Node.js/Chrome" [+] as follow:

webstorm运行/调试配置附加选项

To make the debugger restart after every change you would have to enable the [ x] Reconnect Automatically option.

The flow of working with the debug is:

  1. Run your (in my case) Nodemon.
  2. Debug your (in my case) NodemonDebugger
  3. Set the breakpoints and everything else and you are good to go.

Note: If you are going direct to the debugger instead (and therefore not following this process) one would probably be expecting a termination of the process after changing the code lines.

I am not sure how byebug works. However if you use VSCode and nodemon (installed globally), VSCode can reattach itself to the running process and will break at the same point in the debugger.

Here is what my config file looks like

{
      "name": "Launch server.js via nodemon",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "nodemon",
      "program": "${workspaceFolder}/joiValidation.js",
      "restart": true,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }

Here is the small video I made from my debugging. Official documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM