node.js - 如何在 Visual Studio 代码中调试 nodeJS (ExpressJS) 应用程序?
问题描述
我已经尝试了许多在线可用的不同解决方案,但在我的情况下没有任何效果,我试图在运行时调试 nodeJS 应用程序,通过 UI/postman 调用 API
我的 launch.json:从这里获取指南
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"skipFiles": [
"<node_internals>/**"
]
}
启动本地服务器后,当我启动调试器时,它要求选择一个进程,我选择了一个以--exec babel-node server.js
它结尾的进程,但没有加载我的项目脚本,只有 node_modules、eval 和 node_internal。
在我的代码中,如果我放置断点,我会看到这个错误“断点已设置但尚未绑定”
我的 package.json 开始脚本:
"scripts": {
"start": "nodemon --exec babel-node server.js"
}
我的代码在 ES6 中,我通过一个 shell 脚本启动服务器,该脚本首先设置一些环境,然后执行npm start
我的.bablerc
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
解决方案
这是我的launch.json,我用express运行nodejs,它工作正常。
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js",
"args": ["--env","local"]
}
]
}
推荐阅读
- ruby-on-rails - 如何在 Rails 中使用 Figaro 安全地存储电子邮件凭据
- kubernetes - Kubernetes nginx 入口配置不适用于 Grafana
- openproject - openproject配置抛出“错误1045(28000):用户'root'@'localhost'的访问被拒绝(使用密码:YES)”?
- jquery - 每个使用 jQuery 将 id 设置为 img
- r - 如何使用聚集和传播解决问题?(提迪尔)
- reactjs - 如何在 React 中创建管理页面?
- r - 将包含不等长度字符串的列拆分为R中的多个列
- c - 为 C 中的每一行读取 2 个值的文本文件
- python - 用python分割数据框
- python - Python-将数据附加到 CSV 并打印到新的 CSV