# How do you set a 'node' context variable?

**URL:** <https://discourse.nodered.org/t/how-do-you-set-a-node-context-variable/3519>\
**Category:** General\
**Created:** [27 September 2018 22:53 UTC](https://discourse.nodered.org/t/how-do-you-set-a-node-context-variable/3519 "2018-09-27T22:53:20Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [27 September 2018 22:53 UTC](https://discourse.nodered.org/t/how-do-you-set-a-node-context-variable/3519/1 "2018-09-27T22:53:20Z")

</div>

In the documentation it talks about the 'scope' of a particular context. Global and flow I understand, but not node. To set a flow context variable you use something like  
`flow.set("myData", msg.payload, "storeInFile");`  
and in the sidebar you can see the value.  
 ![21%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d35cbc4b34a2bd2ba572b2531141ea90bc1b93db.png)

There is an area to display `Node` context, but how do you set it? If I use  
`node.set("myData", msg.payload);`  
I get:  
`28 Sep 00:52:14 - [error] [function:Node Stored in memory] TypeError: node.set is not a function`  
so my question: How do you set a node context?

---

<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:** [27 September 2018 23:09 UTC](https://discourse.nodered.org/t/how-do-you-set-a-node-context-variable/3519/2 "2018-09-27T23:09:12Z")

</div>

```auto
context.set("myData", msg.payload);

```

[https://nodered.org/docs/writing-functions#storing-data](https://nodered.org/docs/writing-functions#storing-data)

---

<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:** [28 September 2018 00:22 UTC](https://discourse.nodered.org/t/how-do-you-set-a-node-context-variable/3519/3 "2018-09-28T00:22:13Z")

</div>

Duh (head slap) I must have read that 3 times and it went in and out my head. (Can I blame my head cold?)  
Thanks @knolleary !

---

<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:** [28 September 2018 00:43 UTC](https://discourse.nodered.org/t/how-do-you-set-a-node-context-variable/3519/4 "2018-09-28T00:43:16Z")

</div>

@knolleary  
One more question - when I use `context.set("myData", msg.payload);` It will only show up in the sidebar if I hi-light the node that created it. As soon as I click another node of even click somewhere else on the page, the entry in the sidebar disappears. It will come back if I click on the node and press the refress icon in the sidebar.

Is this expected behavior?

(I'm putting together example flows that might be good for the cookbook.)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [28 September 2018 06:17 UTC](https://discourse.nodered.org/t/how-do-you-set-a-node-context-variable/3519/5 "2018-09-28T06:17:47Z")

</div>

Yes, as the name "node context" implies the context is only valid for that node.
