# Promise can't return msg

**URL:** https://discourse.nodered.org/t/promise-cant-return-msg/53317
**Category:** General
**Created:** [7 November 2021 02:18 UTC](https://discourse.nodered.org/t/promise-cant-return-msg/53317 "2021-11-07T02:18:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![RootShell-coder](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rootshell-coder/32/47167_2.png) [@RootShell-coder](https://discourse.nodered.org/u/RootShell-coder)
#### Post date: [7 November 2021 02:18 UTC](https://discourse.nodered.org/t/promise-cant-return-msg/53317/1 "2021-11-07T02:18:10Z")

</div>

I am trying to use a function with the following seems to be simple code.

settings.js

```auto
    functionGlobalContext: {
        bluebird:require('bluebird')
    },

```

function

```auto
const Promise = context.global.bluebird

const p = new Promise((resolve, reject) => {
    setTimeout(()=>{
        resolve(10)
    }),1000
})

p.then(number => {
    msg.topic = number
    node.warn(msg.topic)
    return msg
})

```

and can't return the msg object. In addition, I still did not understand how to properly connect external modules through the setup tab of the function block.

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [7 November 2021 02:52 UTC](https://discourse.nodered.org/t/promise-cant-return-msg/53317/2 "2021-11-07T02:52:19Z")

</div>

Hello Root,

```auto
const bluebird = global.get("bluebird") // reference library

const p = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(10)
    }, 1000)
})

p.then(number => {
    msg.topic = "My promise number"
    msg.payload = number
    //node.warn(msg.topic)
    node.send(msg)
})

```

1. you were referencing the library wrong ([Documentation](https://nodered.org/docs/user-guide/writing-functions#using-the-functionglobalcontext-option))
2. you had the ms timeout outside the brackets
3. dont know what the library does .. thats up to you 😉

---

<div class="post-metadata">

### Author: ![RootShell-coder](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rootshell-coder/32/47167_2.png) [@RootShell-coder](https://discourse.nodered.org/u/RootShell-coder)
#### Post date: [7 November 2021 03:08 UTC](https://discourse.nodered.org/t/promise-cant-return-msg/53317/3 "2021-11-07T03:08:04Z")

</div>

thank you very much.  
Truly, asynchronous need to be returned via `node.send(msg)` 😌

---

<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: [7 November 2021 08:24 UTC](https://discourse.nodered.org/t/promise-cant-return-msg/53317/4 "2021-11-07T08:24:20Z")

</div>

Do not use `bluebird`. There is no good reason for using that library these days. All supported versions of node.js have full support for `Promise` built in.

---

<div class="post-metadata">

### Author: ![RootShell-coder](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rootshell-coder/32/47167_2.png) [@RootShell-coder](https://discourse.nodered.org/u/RootShell-coder)
#### Post date: [7 November 2021 23:52 UTC](https://discourse.nodered.org/t/promise-cant-return-msg/53317/5 "2021-11-07T23:52:19Z")

</div>

I'm just studying the tool I'm trying to work with. I am reading this wonderful forum and I am asking questions that are incomprehensible to me. But first, in order not to distract the community, I try to figure it out on my own. I think many people do this. Although the above example was simple, it still allowed me to go further. Thank you sincerely for your wonderful knowledge.

---

<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: [21 November 2021 23:52 UTC](https://discourse.nodered.org/t/promise-cant-return-msg/53317/6 "2021-11-21T23:52:24Z")

</div>

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