# How to config get the first value ini file when duplicate keys

**URL:** <https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980>\
**Category:** General\
**Created:** [17 September 2020 04:53 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980 "2020-09-17T04:53:54Z")\
**Posts on this page:** 9\
**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:** [17 September 2020 04:53 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/1 "2020-09-17T04:53:54Z")

</div>

I read an **ini** file with duplicate keys, ie:

```auto
[SESSION]
key1=value1
key1=value2222
xxx=yyy

```

I used the code below to get the contents of the ini file

```auto
var fs = require('fs')
  , ini = require('ini')

var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))

```

In case the key is duplicate, **the last value** is taken.  
The result is:

```auto
[SESSION]
key1=value2222
xxx=yyy

```

I would like to get **the first value** , is it configurable?  
Thanks in advance!

```auto
[SESSION]
key1=value1
xxx=yyy

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [17 September 2020 06:52 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/2 "2020-09-17T06:52:57Z")

</div>

Have you read the documentation of the `ini` module you are using?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 September 2020 06:53 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/3 "2020-09-17T06:53:47Z")

</div>

Why not use the file-in node to read the file. You could read each line as a separate msg then do what you want with them.

---

<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:** [17 September 2020 07:34 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/4 "2020-09-17T07:34:29Z")

</div>

> [@knolleary](#):
>
> Have you read the documentation of the `ini` module you are using?

＞I have read it but have not seen the configuration write to do what I want  
Link: [https://github.com/npm/ini/blob/master/README.md](https://github.com/npm/ini/blob/master/README.md)

> [@zenofmud](#):
>
> Why not use the file-in node to read the file. You could read each line as a separate msg then do what you want with them.

＞Because using the `ini` module, it will be easier to manipulate the contents of the ini file, such as getting _session_, _key_, _value_, ...

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [17 September 2020 07:36 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/5 "2020-09-17T07:36:36Z")

</div>

A quick look at the docs for that module suggest it expects the following syntax for keys that can have multiple values:

```auto
[paths.default]
datadir = /var/lib/data
array[] = first value
array[] = second value
array[] = third value

```

Are you able to change the ini file syntax to match that?

If not, then you won't be able to use the `ini` module and you'll have to figure out how to parse it for yourself using the File In node and some Function code.

---

<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:** [17 September 2020 07:41 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/6 "2020-09-17T07:41:15Z")

</div>

> [@knolleary](#):
>
> If not, then you won't be able to use the `ini` module and you'll have to figure out how to parse it for yourself using the File In node and some Function code.

＞Alright, I understand. Thank you very much.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 September 2020 08:04 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/7 "2020-09-17T08:04:55Z")

</div>

Just out of curiosity, are you creating the ini file in the first place?  
if so, why are you creating the duplicates?

- why couldn't you create a javascript object instead?

```auto
{
    "session": {
        "key1": "value1",
        "xxx": "yyy"
    }
}

```

then you could address it with `session.key1`.

Just a thought.

---

<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:** [17 September 2020 08:10 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/8 "2020-09-17T08:10:52Z")

</div>

Because I want to use with ini file.  
I will take note of your instructions.  
Thank you for your enthusiastic guidance!

---

<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:** [1 October 2020 08:10 UTC](https://discourse.nodered.org/t/how-to-config-get-the-first-value-ini-file-when-duplicate-keys/32980/9 "2020-10-01T08:10:58Z")

</div>

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