# Function node export object from start section

**URL:** <https://discourse.nodered.org/t/function-node-export-object-from-start-section/82049>\
**Category:** General\
**Tags:** function-node, javascript\
**Created:** [15 October 2023 14:20 UTC](https://discourse.nodered.org/t/function-node-export-object-from-start-section/82049 "2023-10-15T14:20:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dakhnod](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dakhnod/32/83782_2.png) [@dakhnod](https://discourse.nodered.org/u/dakhnod)\
**Post date:** [15 October 2023 14:20 UTC](https://discourse.nodered.org/t/function-node-export-object-from-start-section/82049/1 "2023-10-15T14:20:56Z")

</div>

I use a function node to connect to [socket.io](http://socket.io), thus creating a socket object in the Start tab.  
I need access to that socket object in the Stop section, to close the connection again.  
Alternatively, `node.on('close', ...)` would work, but node#on does not seem to be available in the Setup tab.

So here is the question:  
How do I access objects created in the start code from the stop code?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 October 2023 14:47 UTC](https://discourse.nodered.org/t/function-node-export-object-from-start-section/82049/2 "2023-10-15T14:47:08Z")

</div>

> [@dakhnod](#):
>
> How do I access objects created in the start code from the stop code?

By setting a reference in node context.

on start

```auto
context.set('mySocket', mySocket)

```

on stop

```auto
const soc = context.get('mySocket')
soc.whatever()

```

---

<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:** [14 December 2023 14:47 UTC](https://discourse.nodered.org/t/function-node-export-object-from-start-section/82049/3 "2023-12-14T14:47:59Z")

</div>

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