# How should I save the contents of the ini file

**URL:** <https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915>\
**Category:** General\
**Created:** [15 September 2020 14:50 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915 "2020-09-15T14:50:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [15 September 2020 14:50 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915/1 "2020-09-15T14:50:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 September 2020 15:05 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915/2 "2020-09-15T15:05:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 September 2020 15:05 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915/3 "2020-09-15T15:05:22Z")

</div>

> [@minhhn0205](#):
>
> I have an **ini** file that defines the configuration of the Node-RED application created by the user and can change the value

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?

> [@minhhn0205](#):
>
> I think I will save it to a global class

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

> [@minhhn0205](#):
>
> For Node-RED, is it right or should I do it in this case, please help tell me!

#### 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**

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

```

**JSON**

```auto
{
  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](https://flows.nodered.org/node/node-red-contrib-parser-ini) might work for you (I have never used it)

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [15 September 2020 15:15 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915/4 "2020-09-15T15:15:31Z")

</div>

> [@Colin](#):
>
> Can you give us an idea of what is stored in the file so we can better understand the context?

The contents of the ini file look like this:

```auto
[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

```

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [15 September 2020 15:23 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915/5 "2020-09-15T15:23:39Z")

</div>

> [@Steve-Mcl](#):
>
> 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?

Yes

> [@Steve-Mcl](#):
>
> IMO, NO - I would NOT recommend an INI file.

Yes

> [@Steve-Mcl](#):
>
> I guess you mean, store the INI values in an object in node-red for quick / easy access to setting values??

Because user want to use ini file.... ☹

---

<div class="post-metadata">

**Author:** ![minhhn0205](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minhhn0205/32/29062_2.png) [@minhhn0205](https://discourse.nodered.org/u/minhhn0205)\
**Post date:** [15 September 2020 15:35 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915/6 "2020-09-15T15:35:17Z")

</div>

> [@Steve-Mcl](#):
>
> The JSON file would import directly into JS object with properties. (SIMPLE+FAST)

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 September 2020 15:37 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915/7 "2020-09-15T15:37:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 September 2020 15:37 UTC](https://discourse.nodered.org/t/how-should-i-save-the-contents-of-the-ini-file/32915/8 "2020-09-29T15:37:44Z")

</div>

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