# Setup in a Function Node

**URL:** https://discourse.nodered.org/t/setup-in-a-function-node/39445
**Category:** General
**Created:** [20 January 2021 15:48 UTC](https://discourse.nodered.org/t/setup-in-a-function-node/39445 "2021-01-20T15:48:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![LucaCarminati](https://avatars.discourse-cdn.com/v4/letter/l/43a26b/32.png) [@LucaCarminati](https://discourse.nodered.org/u/LucaCarminati)
#### Post date: [20 January 2021 15:48 UTC](https://discourse.nodered.org/t/setup-in-a-function-node/39445/1 "2021-01-20T15:48:44Z")

</div>

Hi to all,  
A probably stupid question...how can I use the setup tab in a function Node?

 ![arr](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/7249a17191f8570f4b5216a62c298bfea5455439.png) ![set](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6fd01c09a87a07ec57b61a73eea4efcbb0eab5ef.png)

I need to set the Var i = 0 for the first time that the function node is called, and then go on with the code written in the function tab.

Is there a special syntax to put in the setup tab?

Thanks to all

---

<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: [20 January 2021 15:52 UTC](https://discourse.nodered.org/t/setup-in-a-function-node/39445/2 "2021-01-20T15:52:37Z")

</div>

Hi @LucaCarminati

Each of the `setup`, `function` and `close` functions run in their own scope. Any variables you declare in one are only visible in that one.

This is where you can use the `context` object - which is shared between the functions.

In this instance you'd do:

```auto
context.set('i',0);

```

in the `setup` tab, and then:

```auto
var i = context.get('i');

```

in the main `function` .

---

<div class="post-metadata">

### Author: ![LucaCarminati](https://avatars.discourse-cdn.com/v4/letter/l/43a26b/32.png) [@LucaCarminati](https://discourse.nodered.org/u/LucaCarminati)
#### Post date: [20 January 2021 15:59 UTC](https://discourse.nodered.org/t/setup-in-a-function-node/39445/3 "2021-01-20T15:59:14Z")

</div>

Hi @knolleary ,

Thanks a lot!  
I have used yet the context var until now, and I thought that the Setup tab could be used for the initial setup of the variables (without using the context); I will use your solution.

Thanks again!

---

<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: [3 February 2021 15:59 UTC](https://discourse.nodered.org/t/setup-in-a-function-node/39445/4 "2021-02-03T15:59:17Z")

</div>

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