# Can node functions return promises?

**URL:** <https://discourse.nodered.org/t/can-node-functions-return-promises/7050>\
**Category:** Developing Nodes\
**Created:** [20 January 2019 14:42 UTC](https://discourse.nodered.org/t/can-node-functions-return-promises/7050 "2019-01-20T14:42:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScottChapman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scottchapman/32/4838_2.png) [@ScottChapman](https://discourse.nodered.org/u/ScottChapman)\
**Post date:** [20 January 2019 14:42 UTC](https://discourse.nodered.org/t/can-node-functions-return-promises/7050/1 "2019-01-20T14:42:05Z")

</div>

Sorry for the noob question, I did poke around but couldn't find anything specific (might not have really known where to look exactly).

Anyway, I am writing my first node, and it looks like I basically create a module and export a function that takes an object as an argument.

I don't know what s expected from that function:

1. What can/should it return?
2. Can it return a promise?
3. (and I guess related to #2) can the function be an async function?

Thanks in advance, just getting started here...

Thanks in advance! (and again, sorry for the noon question)

---

<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 2019 17:23 UTC](https://discourse.nodered.org/t/can-node-functions-return-promises/7050/2 "2019-01-20T17:23:07Z")

</div>

Hi @ScottChapman

the basic structure of the node's javascript file is described here: [https://nodered.org/docs/creating-nodes/first-node#lower-casejs](https://nodered.org/docs/creating-nodes/first-node#lower-casejs)

The Function you export will be called by the runtime when its time to load your node in. The single argument passed to that function is a handle into the Node-RED runtime - by convention, called `RED`. So within your function you would define you custom nodes along with their calls to `RED.nodes.registerType` to get them registered.

The Function can, if it wants, return a Promise.

As Node-RED still supports Node 4, then making your node function async would potentially mean it didn't work for some users.

However with the 0.20 release we'll be dropping Node 4 support so async functions would be okay.

---

<div class="post-metadata">

**Author:** ![ScottChapman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scottchapman/32/4838_2.png) [@ScottChapman](https://discourse.nodered.org/u/ScottChapman)\
**Post date:** [25 January 2019 00:11 UTC](https://discourse.nodered.org/t/can-node-functions-return-promises/7050/3 "2019-01-25T00:11:27Z")

</div>

Perfect thanks!
