Websites & apps

Node.js logs and debugging on cPanel and a VPS

Find where your Node.js app writes its logs on cPanel, PM2 and systemd, read crash messages, add useful logging and debug safely in production.

IntermediatecPanel hosting and Linux VPS2 min read

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 runsWhere to look
cPanel Setup Node.js Appstderr.log in the application root, plus cPanel → Metrics → Errors
PM2pm2 logs NAME, files in ~/.pm2/logs/
systemd servicejournalctl -u NAME
Nginx in front/var/log/nginx/error.log
Dockerdocker logs CONTAINER

Read logs on cPanel

  1. Open cPanel → Files → File Manager and go to your application root (for example /home/USER/nextapp).
  2. Open stderr.log. The newest lines are at the bottom.
  3. If the file is empty, check cPanel → Metrics → Errors for Passenger messages.

Over SSH you can watch it live:

tail -f ~/nextapp/stderr.log

Read logs on a VPS

pm2 logs myapp --lines 200
pm2 logs myapp --err
journalctl -u myapp -n 200 --no-pager
journalctl -u myapp -f

For 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:20

The 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.log and console.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.js
ssh -L 9229:127.0.0.1:9229 deploy@your-server-ip

Then 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.

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.