# Setup node variables in function node on start

**URL:** https://discourse.nodered.org/t/setup-node-variables-in-function-node-on-start/55984
**Category:** General
**Created:** [2 January 2022 07:30 UTC](https://discourse.nodered.org/t/setup-node-variables-in-function-node-on-start/55984 "2022-01-02T07:30:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [2 January 2022 07:30 UTC](https://discourse.nodered.org/t/setup-node-variables-in-function-node-on-start/55984/1 "2022-01-02T07:30:07Z")

</div>

Hi folks,

My first question in 2022, and it is a noob level one. First time that I use the "On start" tabsheet in the function node...

All my code in the "On start" tabsheet is executed correctly, but when I add this:

```auto
node.workers = [];

```

And I use that node variable in my "On message" tabsheet:

```auto
node.workers.push(...);

```

Then I get `"TypeError: Cannot read property 'push' of undefined"` in my Debug sidebar.

I suppose it is something ridiculous, but can't see it. When I debug the code, the `node` variable is nicely available and I can use it here e.g. to show an initial node status.

Thanks!!!  
Bart

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [2 January 2022 07:41 UTC](https://discourse.nodered.org/t/setup-node-variables-in-function-node-on-start/55984/2 "2022-01-02T07:41:28Z")

</div>

Hmm, don't think it has anything to do with my startup tabsheet.

1. For the first message that I inject, an element is added correctly to my array:

2. When I inject another message my array is undefined again:

I am ready for the madhouse at the moment...

---

<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: [2 January 2022 09:02 UTC](https://discourse.nodered.org/t/setup-node-variables-in-function-node-on-start/55984/3 "2022-01-02T09:02:28Z")

</div>

Use `context` not `node` to store values across different calls to the function

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [2 January 2022 09:06 UTC](https://discourse.nodered.org/t/setup-node-variables-in-function-node-on-start/55984/4 "2022-01-02T09:06:14Z")

</div>

Thanks Nick!  
Not sure how I could have overlooked that ...

---

<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: [16 January 2022 09:06 UTC](https://discourse.nodered.org/t/setup-node-variables-in-function-node-on-start/55984/5 "2022-01-16T09:06:34Z")

</div>

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