I recently had a problem with NodeRed that caused the NodeRed process to crash sometimes.
Not really that bad because it is restarted automatically. On the other hand, it annoyed me at some point because the data in the dashboard view was lost and status messages were sent every time.
So it was time to get to the bottom of it. First I checked the journal of the NodeRed service vai “sudo journal -f -u nodered”.
This command shows all status messages that are stored in the journal of the service. I was actually only interested in the last messages before NodeRed was restarted.
For this purpose, I created the flow shown below. Each time after the restart of NodeRed, this saves the contents of the journal in the folder “/home/pi/nodeRedLogFiles”.
If you are looking for an error that leads to a restart, you should find it quickly thanks to this. 🙂
Inhalte
Safety instructions
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/sicherheitshinweise/
Affiliate links / advertising links
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
Requirements
Helpful Articles:
So that you can install new nodes, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.
RaspberryPi – Setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
NodeRed – Installation of NodeRed on the RaspberryPi
Required tools:
-none-
Required material:
In the following list you will find all the parts you need to implement this article.
Log in to the NodeRed configuration interface
Before you can edit your NodeRed configuration you must - if activated - first log in to the NodeRed configuration interface.

Import node code
To test this code, you can simply import the code below into your NodeRed installation. You can find tips on this in the article NodeRed – Importing and exporting node code.

[{"id":"185f8c16.a86d64","type":"exec","z":"2dcf0cc0.aeb894","command":"journalctl -u nodered -all","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"last","x":410,"y":3480,"wires":[["30e6e36b.45d3fc"],[],[]]},{"id":"30e6e36b.45d3fc","type":"function","z":"2dcf0cc0.aeb894","name":"prepare filename","func":"\nvar d = new Date();\nvar t = d.getTime();\nvar year = d.getFullYear();\nvar month = d.getMonth()+1; \nvar day = d.getDate();\nvar hour = d.getHours();\nvar minute = d.getMinutes();\n\nif(month.toString().length == 1) \n{\n month = '0'+month;\n}\n\nmsg.filename = \"/home/pi/nodeRedLogFiles/nodeRedLog_\"+day+\"-\"+month+\"-\"+year+\"-\"+hour+\":\"+minute+\".csv\";\n\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":3480,"wires":[["9f916f6c.d00cb"]]},{"id":"519cb1ab.0032b","type":"inject","z":"2dcf0cc0.aeb894","name":"save last nodered-journal","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":210,"y":3480,"wires":[["185f8c16.a86d64"]]},{"id":"9f916f6c.d00cb","type":"file","z":"2dcf0cc0.aeb894","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":810,"y":3480,"wires":[[]]},{"id":"510d4143.de0cb","type":"comment","z":"2dcf0cc0.aeb894","name":"Save last journal nodered","info":"","x":170,"y":3420,"wires":[]}]
View in the dashboard
View of the collected NodeRed journals
In the folder “/home/pi/nodeRedLogFiles” on your RaspberryPi you will find the saved NodeRed logs that are saved after every restart of NodeRed.

I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
Fab
P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂
