# List of all global

**URL:** <https://discourse.nodered.org/t/list-of-all-global/49567>\
**Category:** General\
**Created:** [10 August 2021 12:26 UTC](https://discourse.nodered.org/t/list-of-all-global/49567 "2021-08-10T12:26:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xeniluom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xeniluom/32/46352_2.png) [@Xeniluom](https://discourse.nodered.org/u/Xeniluom)\
**Post date:** [10 August 2021 12:26 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/1 "2021-08-10T12:26:07Z")

</div>

Hi,  
I am looking for a method to retrieve the name of the global variables as well as their value.

For the moment, I only manage to have an array with the values:  
global.get (global.keys ())

I can't get the name of the variables the same way they are displayed in the context

![Sans titre](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e6869a386e4e3542baa668f6c47ef7efe85b361c.png)

Can anyone tell me how to do this?  
thanks

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 August 2021 12:43 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/2 "2021-08-10T12:43:28Z")

</div>

Usually you know the global property you used to save the value in the first place and you retrieve it with  
For example: `let progress1 = global.get('progress1')`

You could use a Function node to generate the list by looping through the keys

```javascript
let list = []

global.keys().forEach( key => {
    list.push( { [key]: global.get(key)});
})

msg.payload = list
return msg

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 August 2021 14:04 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/3 "2021-08-10T14:04:08Z")

</div>

To use global.keys(), you need to have the following in settings.js:

```auto
exportGlobalContextKeys: true,

```

Since that is actually a bit of a security issue if you allow people access to the full list all the time.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 August 2021 14:11 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/4 "2021-08-10T14:11:14Z")

</div>

Thats strange .. i checked my `settings.js` and indeed its set to `exportGlobalContextKeys: false` by default but the above code run regardless.

Node-RED version: v2.0.5  
Node.js version: v14.16.0

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 August 2021 14:35 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/5 "2021-08-10T14:35:19Z")

</div>

Ah, interesting, is that a bug I wonder?

---

<div class="post-metadata">

**Author:** ![Xeniluom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xeniluom/32/46352_2.png) [@Xeniluom](https://discourse.nodered.org/u/Xeniluom)\
**Post date:** [10 August 2021 14:56 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/6 "2021-08-10T14:56:55Z")

</div>

Thanks, it's exactly what I want 🙂

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 August 2021 15:34 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/7 "2021-08-10T15:34:25Z")

</div>

@Xeniluom cool .. now that i think of it maybe it would be more easily accesible if the list was an object.

```javascript
let list = {};

global.keys().forEach( key => {
    list[key] = global.get(key);
})

msg.payload = list
return msg

```

@TotallyInformation seems like it.

---

<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:** [10 August 2021 15:53 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/8 "2021-08-10T15:53:59Z")

</div>

`exportGlobalContextKeys` controls whether the global context keys set via `functionGlobalContext` are exposed or not.

Any global context properties set in the flow itself will always be returned.

---

<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:** [24 August 2021 15:54 UTC](https://discourse.nodered.org/t/list-of-all-global/49567/9 "2021-08-24T15:54:51Z")

</div>

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