# Environment variables only strings?

**URL:** <https://discourse.nodered.org/t/environment-variables-only-strings/48867>\
**Category:** General\
**Created:** [25 July 2021 04:19 UTC](https://discourse.nodered.org/t/environment-variables-only-strings/48867 "2021-07-25T04:19:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blunoz](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@blunoz](https://discourse.nodered.org/u/blunoz)\
**Post date:** [25 July 2021 04:19 UTC](https://discourse.nodered.org/t/environment-variables-only-strings/48867/1 "2021-07-25T04:19:37Z")

</div>

I've set up a file external to my settings.js to store device specific configuration data as discussed in this thread [Environment variables outside settings.js file - General - Node-RED Forum (nodered.org)](https://discourse.nodered.org/t/environment-variables-outside-settings-js-file/26527)

in settings.js:

```auto
var	env_external = require("./device_settings");

```

device\_settings.js

```auto
module.exports = {
	relay_boards: process.env.RELAY_BOARDS = [0, 2, 4], // array of relay board ids
}

```

Are all environment variables stored as a string?

When I do this in a function:

`global.set("relay_boards",env.get("RELAY_BOARDS")); // array of id's of boards`

Then the global variable is a string "0, 2, 4" when I want it to be an array [0, 2, 4];

---

<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:** [25 July 2021 06:08 UTC](https://discourse.nodered.org/t/environment-variables-only-strings/48867/2 "2021-07-25T06:08:59Z")

</div>

The `process.env` object forces all properties to type string because environment variables must always be strings.

  

If it just your intention to set a global variable it would be far easier to simply read the file in your flow using a `file` node.

Store the settings in a JSON file then use a `file` node then a `JSON` node (to convert the JSON to an object) then get the values from `msg.payload`

#### device\_settings.json

```auto
{
   "relay_boards": [0, 2, 4],
   "another_setting": 123,
   "one_more": "hello from device_settings.json"
}

```

#### function

```auto
global.set("relay_boards",msg.payload.relay_boards);

```

  

* * *
  

alternatively, if you want to pursue env vars, you could recreate the array in the function...

```auto
global.set("relay_boards",env.get("RELAY_BOARDS").split(","));

```

---

<div class="post-metadata">

**Author:** ![blunoz](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@blunoz](https://discourse.nodered.org/u/blunoz)\
**Post date:** [25 July 2021 07:19 UTC](https://discourse.nodered.org/t/environment-variables-only-strings/48867/3 "2021-07-25T07:19:13Z")

</div>

Thanks for the quick advice Steve! That solution should work perfectly!

---

<div class="post-metadata">

**Author:** ![Lupin\_III](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lupin_iii/32/67650_2.png) [@Lupin\_III](https://discourse.nodered.org/u/Lupin_III)\
**Post date:** [26 July 2021 10:20 UTC](https://discourse.nodered.org/t/environment-variables-only-strings/48867/5 "2021-07-26T10:20:54Z")

</div>

Yes, at the and I even used a json file. On a js I could help you more

---

<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:** [9 August 2021 10:21 UTC](https://discourse.nodered.org/t/environment-variables-only-strings/48867/6 "2021-08-09T10:21:13Z")

</div>

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