在 Linux 上用 Node.js 启动程序“没有任何日志输出”,常见原因和对应解决办法如下,你可以按顺序排查:
ps -ef | grep node
或
ps aux | grep node
常见启动方式问题:
node app.js > /dev/null 2>&1 &
✅ 解决:
node app.js > app.log 2>&1 &
tail -f app.log
或用 nohup:
nohup node app.js > app.log 2>&1 &
确保有:
console.log('server start')
process.exit() 太快console.log('start')
process.exit(0) // 可能来不及 flush
✅ 改为:
console.log('start')
node app.js
如果有报错,马上能看到。
npm install)如果你是用 systemd:
journalctl -u your-service -f
service 文件示例:
[Service]
ExecStart=/usr/bin/node /path/app.js
StandardOutput=journal
StandardError=journal
pm2 logs
或
pm2 show app
如 winston / pino:
node app.js # 前台看错误
nohup node app.js & # 后台
tail -f nohup.out
如果你愿意,可以把:
发出来,我可以直接帮你定位。