How should I save the contents of the ini file

Hello Everyone,

I'm completely new to node-red and javascript.
I have an ini file that defines the configuration of the Node-RED application created by the user and can change the value.

After reading the contents of the ini file, I think I will save it to a global class and then the nodes will call and retrieve data from this global class.

For Node-RED, is it right or should I do it in this case, please help tell me!
Any hint will be great.
Thanks.

Can you give us an idea of what is stored in the file so we can better understand the context?

1 Like

If I understand you, you have settings that are to be used in a flow, stored in an INI file that you want node-red to read?

I guess you mean, store the INI values in an object in node-red for quick / easy access to setting values??

IMO, NO - I would NOT recommend an INI file.

JavaScript works much better with JSON (which stands for JavaScript Object Notation)

Here is an example of the difference...

INI

[global]
max_users=12
title=hello
dept=office1
ep1=http://docs.local

JSON

{
  global: {
    max_users: 12,
    title: "hello",
    dept: "office1"
    ep1: "http://docs.local"
  }
}
  • The INI would have to be specially parsed / converted to a JS object with properties. (DIFFICULT+SLOW)
  • The JSON file would import directly into JS object with properties. (SIMPLE+FAST)

Mind you - if you MUST stay on INI files, this might work for you (I have never used it)

1 Like

The contents of the ini file look like this:

[GROUP1]
Key1=Value1
Key2=Value2
Key3=Value3
Key4=Value4

[GROUP2]
KeyX=ValueX
KeyY=ValueY

[GROUP1]
Key1=ValueA  // Because the same [GROUP1] and Key1 should ignore not storing data
Key5=Value5

Yes

Yes

Because user want to use ini file.... :frowning:

If I use JSON file, how should I save the data? Can you hint for me?

Same way you would save an ini file.

JSON is just text

JSON = JavaScript Object Notation

i.e. a string representation of a JS object.

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