通过node-inspector或VSCode调试服务器上代码

https://www.cnblogs.com/chyingp/p/node-debug.html

 

使用node-inspector

在服务器上全局安装 node-inspector
npm install -g node-inspector

调试方式一:
1、在服务器上使用 node-debug 直接启动要调试的程序
node-debug app.js

2、使用本地chrome通过服务器ip地址访问调试界面
http://*.*.*.*:8080/?port=5858

调试方式二:
首先,在服务器上启动 node-inspector 服务
node-inspector

其次,通过 --debug-brk 参数启动要调试的程序
node --debug-brk app.js

最后,使用本地chrome通过服务器ip地址访问调试界面
http://*.*.*.*:8080/?port=5858

注意需保证服务器8080端口可以被访问

 

使用VSCode

1、启动程序时加--inspect
node --inspect=0.0.0.0:指定调试端口号 app.js
不指定端口号,默认9229

如果使用pm2启动程序可在启动配置中添加如下选项
{
  ...
  node_args: ['--inspect=0.0.0.0:指定调试端口号']
}

2、VSCode添加调试配置
{
  "type": "node",
  "request": "attach",
  "name": "服务器调试",
  "address": "*.*.*.*",    // 服务器IP
  "port": *****,             // 启动程序时,指定的调试端口号
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "程序在服务器上的绝对路径",
  "skipFiles": [
    "<node_internals>/**"
  ]
}

注意需保证服务器调试端口可以被访问

 

posted @ 2021-02-18 15:54  刘镇维  阅读(358)  评论(0编辑  收藏  举报