Node-Red Persistence

Node-Red Persistence

How could I POSSIBLY be so SLOW? For many months, after originally coming up with my own mechanism for making Node-Red variables persistent across power cycling – and then promptly forgetting about it, I’ve been conveniently ignoring the relatively new official way to do this…

This morning, just out of boredom I thought I’d have a read up… and…

Making this SIMPLE change to the Node-Red settings.js file inside the module exports section somewhere (in my case in /home/pi/.node-red folder) does it ALL.

contextStorage: {
default    : { module: “localfilesystem”}

That’s IT. So now, for any global for example, I just do this (below) in the first tab (at the top) of my Node-Red installation using an INJECT node to work once only on initialise. Unlike before, that init will only happen in the unlikely event that my settings file has been corrupted, normally no change will be made on boot as the variable will exist already.

global.set(“sidewallRGB”,global.get(“sidewallRGB”) || “255,255,255”);

Now, clearly the variables are automatically written to a file. to minimise SD wear this apparently is cached for 30 seconds so worse case if you lose power, you could lose the last 30 seconds of change… but that’s FAR better than losing all your values every time you reboot the computer (Raspberry Pi or whatever).

I found THIS helpful discussion:


8 thoughts on “Node-Red Persistence

  1. hello Pete

    I am running V1.0 beta 4

    I put contextStorage: {
    default : { module: “localfilesystem”}
    in my settings.js file in .node-red directory and could not get node-red flow or ui on firefox after I entered it, but I could ssh into directory and erase the entry, after which firefox could get node-red ui and flow.

    see my comments in Node-Red 1.0 b3 Trials

    regards Brian

    1. I tried the same and it didn’t like it, so i erased it, then i tried putting it on the folder usr something settings.js, but it doesnt keep the context upon reboot any help with that?

      1. That’s the one! A very good tool to troubleshoot the projects. If you tried the NodeRed 1.0 you might also like the subflow variables which now has persistent state baked into it.

        No more dodgy configs for flows.. just pick the preferred values in subflow and deploy.

          1. It’s the same thing. It’s an awesome thing! 🙂 now 1.0 and the persistent variables in subflows and I’m very happy!

Comments are closed.