When a Node.js app fails, the answer is almost always in its logs. The hard part is knowing where they are. This guide lists the log locations for each way of running Node.js and shows how to turn a stack trace into a fix.
Before you start
- Access to cPanel File Manager, or SSH to your server.
- The name of your app (PM2 name, systemd unit or cPanel application root).
Where the logs are
| How the app runs | Where to look |
|---|---|
| cPanel Setup Node.js App | stderr.log in the application root, plus cPanel → Metrics → Errors |
| PM2 | pm2 logs NAME, files in ~/.pm2/logs/ |
| systemd service | journalctl -u NAME |
| Nginx in front | /var/log/nginx/error.log |
| Docker | docker logs CONTAINER |
Read logs on cPanel
- Open cPanel → Files → File Manager and go to your application root (for example
/home/USER/nextapp). - Open
stderr.log. The newest lines are at the bottom. - If the file is empty, check cPanel → Metrics → Errors for Passenger messages.
Over SSH you can watch it live:
tail -f ~/nextapp/stderr.logRead logs on a VPS
pm2 logs myapp --lines 200
pm2 logs myapp --errjournalctl -u myapp -n 200 --no-pager
journalctl -u myapp -fFor proxy errors such as 502 or 504 check the web server log too: Nginx access and error logs.
Read a stack trace
A crash looks like this:
TypeError: Cannot read properties of undefined (reading 'id')
at getUser (/home/deploy/myapp/src/users.js:42:18)
at /home/deploy/myapp/src/routes.js:15:20The first line is the error. The first stack line that points to your files (not node_modules) is usually where to look: here users.js line 42.
Log better
- Log to stdout and stderr with
console.logandconsole.error; PM2, Passenger and systemd capture both. - Catch unhandled errors so they reach the log:
process.on('unhandledRejection', (err) => { console.error('Unhandled rejection:', err); }); - For larger apps use a structured logger such as
pino. - Never log passwords, tokens or payment data.
Debug a running app
On a VPS you can start the inspector bound to localhost and connect over an SSH tunnel:
node --inspect=127.0.0.1:9229 server.jsssh -L 9229:127.0.0.1:9229 deploy@your-server-ipThen open chrome://inspect in Chrome on your computer. Never bind the inspector to a public address.
Next steps
Stuck? Our 24/7 team can help: open a support ticket.
