在 Ubuntu 上查看 Node.js 日志,取决于你的运行方式和日志配置。下面按常见情况给你总结:
node app.js
日志直接打印在终端。
nohup node app.js > app.log 2>&1 &
查看日志:
tail -f app.log
pm2 logs
查看某个应用:
pm2 logs appname
pm2 logs --lines 100
~/.pm2/logs/
如果你用 systemctl 启动 Node.js 服务:
journalctl -u your-node-service
实时查看:
journalctl -u your-node-service -f
查看最近 100 行:
journalctl -u your-node-service -n 100
docker logs container_name
实时日志:
docker logs -f container_name
默认输出到 stdout / stderr
日志通常在:
/var/log/
项目目录/logs/
# 查看 Node 进程
ps aux | grep node
# 查看端口占用
lsof -i:3000
# 查看 CPU / 内存
top
如果你能说明:
我可以给你更精确的命令。