Update text file content

Hey All,
I'm quite new in Node-RED development and problably this will be an easy question for the Node-RED expert...
Anyway, I'm using a text file to load some "application" settings when Node-RED is launched (start-up).
By the Node-RED dashboard, some of these settings can be modified by the user as prefer.
When Node-RED is shutted down, I need to update the settings file with the last settings values set by the user.
So:

  • how to recognize that Node-RED is shutting down and "run a shutdown flow" to save the last settings values?
  • how to update the settings file (text) with last settings values? Only the modified settings params should be saved into the file, to avoid to re-write the entire file.

Please let me know.
Thanks a lot

Why? Is the file very large?

Tbh, I would either

  • store settings in an object & serialise it (run it through a JSON node) and save it to file.
    OR
  • Use file backed context.

What operating system are you running Node-Red on?
Why do you want to defer updating the data in the file until node-red is shut down?
Why do you want to avoid rewriting the entire file? How big is it?

Have you looked at persistent context? https://nodered.org/docs/user-guide/context

Hi Steve-Mcl,
thanks for reply.
The file is not so large but the I would like to treat it as an ini windows file...
Can you clarify a little better the two solutions you mentioned?
Thank you very much.

Hi jbudd,

  • OS: Windows 10
  • File updating at the node-red shut down becuase all the settings are passed to some global var that can be modified by the user (via dashboard) and this is one way to avoid continuously file writing.
  • To avoid continuously file writing...anyway the file is not so big.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.