Read log with journalctl when Node-RED is started with pm2

I have installed Node-RED on Linux using the recommended way with npm and autostarting it with pm2.

After a bit of digging, I found the Node-RED log file in /home/USERNAME/.pm2/logs/node-red-out.log

Right now, I read the log file using "tail -n 50 /home/USERNAME/.pm2/logs/node-red-out.log"

How can I access this log file the "ordinary" way using a commands like "journalctl -f -u node-red -o cat"?

The "tail..." works fine but have to be invoked manually for a fresh log. The "journalctl..." gives a live view of the log.

1 Like

Which Linux?

If it is a Debian based system then the recommended way is Running on Raspberry Pi : Node-RED and using systemd to run node red.

Otherwise, to answer your question, you should be able to use an exec node to run the command.

1 Like

Thanks for the quick response Colin.

Right now, I run on RPi/Debian due to hardware unreliabilities on my NUC/Proxmox machine but I believe I had the same "problem" running on Linux Mint.

I would like to run "journalctl..." in terminal on my laptop via ssh.

Do you have a link to this recommendation?

Mint is also Debian based so the recommendation is to use the script I linked to, and use systemd to run it. The script will automatically set that up.

As I said, you should be able to run journalctl in an exec node. Set it to Spawn mode so it outputs the log on the fly.

2 Likes

I dont think you can put pm2's managed app logs in a systemd's journal. Maybe you should create your systemd service definition file.
After googling i discovered that pm2 generates a systemd doc that manages its own process using systemd, not the app's. That is probably the reason you can't see app logs using journals.
Pm2 logs doc page PM2 - Logs

1 Like

I was not aware (enough) that I should use the Pi script on Mint... my bad...

Still waiting for new hardware to reinstall Node-RED on Proxmox/Mint...

Thank you all for your input :+1:

Not really sure why you want to use PM2 when running on Linux and certainly not for a "production" setup. I only use it on Windows for a dev setup that isn't always running (well, actually it now kind of is always on since I start it automatically a few seconds after logging into my usual desktop user).

Run it with systemd instead and the logs will already be using the journal. And you can do most of what you might want with PM2. The only possible exception being auto-restart on watched file changes.

1 Like

recommended here: Starting Node-RED on boot : Node-RED
...but I'm now aware that the Pi-script is a better way...

Don't forget there is a command node-red-log, a bash script, which reads the Node-red logs (using journalctl) - assuming you are on Debian and installed with the official script.

To start Node-red on boot it's sudo systemctl enable node-red
Edit: oops!
To start Node-red on boot it's sudo systemctl enable nodered
I do wish whoever invented 'Node-red' hadn't used that hyphen!

2 Likes

That link says

Raspberry Pi, Debian, Ubuntu

The Raspberry Pi install script we provide can be used on any Debian-like operating system.
This script installs Node-RED as a systemd service. For more information, read the Running on Raspberry Pi guide.

The assumption is made, I think, that anyone running one of the numerous Debian/Ubuntu spinoffs will know that it is based on Debian.

Yor're right. I always read manuals but sometimes the reading is a bit too fast (like skipping all ridiculous and unnecessary safety warnings)... In this case I guess I stopped reading that sentence at "Raspberry"...

Somewhere in the back of my head, there is a memory of the Raspberry install script is installing a way older version of Node-RED than the npm install but this is not the case today where both install methods install ver 4.1.0.

That has never been the case. Possibly you are thinking of the situation if node-red is installed from the OS repositories, which will almost always be out of date, if it is present. For example, Debian Bullseye on the pi currently has v2.2.3 available for install.

1 Like