在 Debian 上调试 Node.js,常见方式有以下几种,按使用频率和实用性给你一个清晰清单。
console.log('value =', value);
适合临时排查,不适合复杂问题。
node inspect app.js
或旧写法:
node --debug-brk app.js
cont / c 继续执行
next / n 单步
step / s 进入函数
out / o 跳出函数
repl 进入交互环境
适合无 GUI 服务器环境。
.vscode/launch.json{
"type": "node",
"request": "launch",
"name": "Debug Node",
"program": "${workspaceFolder}/app.js"
}
node --inspect=0.0.0.0:9229 app.js
sudo ufw allow 9229
{
"type": "node",
"request": "attach",
"name": "Remote Debug",
"address": "服务器IP",
"port": 9229
}
node --inspect app.js
打开:
chrome://inspect
点击 Remote Target → inspect
适合前端 + Node 混合调试。
node --inspect-brk app.js
⚠️ 不要长期开 --inspect,有安全风险
which node
sudo apt install nodejs npm
或:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
✅ 开发:VS Code + --inspect
✅ 服务器:VS Code Remote + SSH
✅ 紧急排查:node inspect
如果你愿意,可以告诉我:
我可以给你精准配置示例。