Node.js调试流程 [英] Node.js Debugging flow

查看:94
本文介绍了Node.js调试流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调试像rails一样的node.js。
我尝试了几种方法:

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


  1. Webstorm调试–在这种情况下,每次操作后,我都需要单击重新运行调试代码已更改

  2. 带有chrome远程调试器的Nodemon –在这种情况下,每次由nodemon重新加载代码后,我每次都需要重新连接到调试器

  3. pry.js –在这里,我需要输入 eval(pry.it) –并没有使其更简单的选项,例如 debug或pry()

那么调试像byebug这样的节点应用程序的最佳选择是什么?

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

升级:

Thx到@AbhinavD我已经在VSCode中做到了:
首先,您需要编辑app / .vscode / launch.js
javascript
{
version: 0.2.0,
configuration:[
{
type: node,
request: attach,
名称:节点:Nodemon,
processId: $ {command:PickProcess},
重新启动:true,
协议:检查器 ,
},
]
}

现在,nodemon在更改后重新启动服务器,并且VSCode自动重新连接到调试器。

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.

查看视频 https://vimeo.com/267975071

在WebStorm中有人可以做到吗?

Is anybody able to do it in WebStorm?

推荐答案

我不确定 byebug 的工作方式。但是,如果您使用VSCode和nodemon(全局安装),则VSCode可以将自身重新附加到正在运行的进程中,并会在调试器的同一点中断。

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.

配置文件看起来像

{
      "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

这篇关于Node.js调试流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆