# Can't strore large variables in global context

**URL:** <https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516>\
**Category:** General\
**Created:** [7 January 2019 15:33 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516 "2019-01-07T15:33:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![malinthasa](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@malinthasa](https://discourse.nodered.org/u/malinthasa)\
**Post date:** [7 January 2019 15:33 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/1 "2019-01-07T15:33:01Z")

</div>

I am trying to store a variable(string) around `6000` size in global context.

```
        let globalContext = this.context().global;
        globalContext.set("myData", stringData);

```

But the retrieved variable has only around `1000` characters.

Can't I/Shouldn't I store lage variables in the`global context`.

What is the proper way to store/retrieve a large variable globally?

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [7 January 2019 15:42 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/2 "2019-01-07T15:42:55Z")

</div>

If you retrieve that large variable and send it to a `debug` node, then the debug node will only show the first 1000 characters or so -- this does _not_ mean that the global context is incorrect. To verify that what you get out is the same a what you put into the context, check the box on the debug node labelled "system console" and you will see the same data is printed in the console log (strangely enough!)

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [7 January 2019 16:22 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/3 "2019-01-07T16:22:33Z")

</div>

Incidentally, I just checked the info sidebar for the debug node and was surprised to see that there is no mention of the displayed data being truncated at xxx bytes -- or how to view the full msg data. It does say the "status" msgs will be truncated at 32 chars. Perhaps the sidebar max settings would be a good thing to note as well...

---

<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:** [8 January 2019 09:52 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/4 "2019-01-08T09:52:35Z")

</div>

If you are storing it using filesystem, then you could check it by looking in the `.node-red` folder and then in the `context` folder then to the `global` folder and check it out there.

---

<div class="post-metadata">

**Author:** ![malinthasa](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@malinthasa](https://discourse.nodered.org/u/malinthasa)\
**Post date:** [8 January 2019 10:49 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/5 "2019-01-08T10:49:50Z")

</div>

Thank you for the response. I tried again and ended up with the same result.

I will show my code.

Following is the part of the code where I set the global context variable.

```
            let globalContext = this.context().global;
            console.log("Stored data length " + temp.length);
            globalContext.set("MyData", temp);

```

Here I got `6374` characters in the stored message.

I retrieve this context variable in my side bar. Following is a simple version of the code.

`data["memory"]["MyData"]["msg"].length` which gives 1003 characters.

While debugging I captured the object.

```
{MyData: {…}}
MyData:
format: "string[6792]"
msg: "{"xxxx..."
__proto__ : Object
__proto__ : Object

```

And there I can see the msg holds data but it has `...` indicating more data which is not there.

Is there any problem in my storing or retrieving code?  
​​​

---

<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:** [8 January 2019 10:53 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/6 "2019-01-08T10:53:38Z")

</div>

As has been explained, the Debug sidebar only shows the first 1000 bytes of data. The same is true of the Context sidebar.

This is why it has been suggested you write the data to a file to independently verify its contents.

---

<div class="post-metadata">

**Author:** ![malinthasa](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@malinthasa](https://discourse.nodered.org/u/malinthasa)\
**Post date:** [8 January 2019 10:55 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/7 "2019-01-08T10:55:56Z")

</div>

I got the result on the browser debug window.

Problem is getting an incorrect length for the length of retrieved data.

`data["memory"]["MyData"]["msg"].length`

---

<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:** [8 January 2019 10:56 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/8 "2019-01-08T10:56:37Z")

</div>

> [@malinthasa](#):
>
> I got the result on the browser debug window.
> 
> Problem is getting an incorrect length for the length of retrieved data.

How are you writing the data to the browser debug window? Where has `data` come from?

---

<div class="post-metadata">

**Author:** ![malinthasa](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@malinthasa](https://discourse.nodered.org/u/malinthasa)\
**Post date:** [8 January 2019 10:58 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/9 "2019-01-08T10:58:53Z")

</div>

I am on the front end of my side bar. In sidebar HTML, in a script, I am calling the `context/global` API endpoint

```
$.getJSON('context/global', function (data) {
        for (var store in data) {
            if (data.hasOwnProperty(store)) {
                if (data[store].hasOwnProperty('MyData'))                 
                 content = data[store]['MyData']['msg'];
```

---

<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:** [8 January 2019 12:52 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/10 "2019-01-08T12:52:17Z")

</div>

> [@malinthasa](#):
>
> In sidebar HTML, in a script, I am calling the `context/global` API endpoint

> [@knolleary](#):
>
> As has been explained, the Debug sidebar only shows the first 1000 bytes of data. **The same is true of the Context sidebar.**

What I didn't spell out in this reply, is the Context sidebar uses the `/context` api ... so the actual truncation is in that API. If you are using that API, you will get truncated data.

What are you using the global context for in your custom sidebar?

---

<div class="post-metadata">

**Author:** ![malinthasa](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@malinthasa](https://discourse.nodered.org/u/malinthasa)\
**Post date:** [8 January 2019 12:57 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/11 "2019-01-08T12:57:33Z")

</div>

I have one node which aggregates a content. Once the content is ready, I am using a button in the sidebar to send that content to remote endpoint. In this scenario, I store the content in the global context variable to make it visible to the call perform in the sidebar. Simply I need to write data from a flow node and access it from my sidebar.

---

<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:** [8 January 2019 12:59 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/12 "2019-01-08T12:59:09Z")

</div>

If it isn't data to be used in the flow itself, can you not store it in a local variable within your code and add your own custom admin http end point for your sidebar to call?

---

<div class="post-metadata">

**Author:** ![malinthasa](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@malinthasa](https://discourse.nodered.org/u/malinthasa)\
**Post date:** [8 January 2019 13:01 UTC](https://discourse.nodered.org/t/cant-strore-large-variables-in-global-context/6516/13 "2019-01-08T13:01:49Z")

</div>

Yes, that would be possible, Thank you very much for pointing it out.

I used the global context storage as I thought it is the best way. Anyway I will proceed with creating an admin endpoint.
