在 Ubuntu 上“关闭 Node.js 日志”要分情况看:日志是谁产生的、写到哪里了。下面按常见场景给你说明,基本都能覆盖。
node app.js > /dev/null 2>&1 &
> /dev/null:标准输出丢弃2>&1:错误输出也丢弃✅ 适合临时跑程序
如果你用 PM2 管理 Node 服务:
pm2 stop app
pm2 delete app
pm2 start app.js --no-log
pm2 flush
如果你是用 systemd 启动 Node:
journalctl -u your-node-service
编辑服务文件:
sudo systemctl edit your-node-service
加入:
[Service]
StandardOutput=null
StandardError=null
然后:
sudo systemctl daemon-reload
sudo systemctl restart your-node-service
error 或 offnode app.js >> /dev/null
如果你以为是 Node 日志,其实是 Nginx:
sudo nano /etc/nginx/nginx.conf
注释或改为:
access_log off;
error_log /dev/null;
node app.js > /dev/null 2>&1
配合:
你可以先运行:
ps aux | grep node
journalctl -u node*
ls /var/log | grep node
如果你愿意,可以把 你是怎么启动 Node 的(命令行 / PM2 / systemd / Docker)告诉我,我可以给你精确的一条命令方案。