# Not getting msg from function node

**URL:** https://discourse.nodered.org/t/not-getting-msg-from-function-node/4029
**Category:** General
**Created:** [16 October 2018 13:25 UTC](https://discourse.nodered.org/t/not-getting-msg-from-function-node/4029 "2018-10-16T13:25:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)
#### Post date: [16 October 2018 13:25 UTC](https://discourse.nodered.org/t/not-getting-msg-from-function-node/4029/1 "2018-10-16T13:25:33Z")

</div>

I'm new to node so I'm pretty sure I'm doing something wrong. I'm trying to take the error, status, or deviceinfo based on what is returned by the create function. If I log them to the console they return fine, but when I try to add them as properties to the msg object I get nothing back.

```
var iothub = global.get('iothub');
var connectionString = '';
var registry = iothub.Registry.fromConnectionString(connectionString);

// Create a new device
var device = {
    deviceId: 'sample-device-'
};

registry.create(device, function(err, deviceInfo, res) {
    if (err) msg.err = err.toString();
    if (res) msg.res = res.statusMessage;
    if (deviceinfo) msg.info = JSON.stringify(deviceInfo);
});

console.log(msg); //shows undefined in the console

return msg; //nothing is returned
```

---

<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: [16 October 2018 13:38 UTC](https://discourse.nodered.org/t/not-getting-msg-from-function-node/4029/2 "2018-10-16T13:38:16Z")

</div>

Hi

you are setting the msg properties in an asynchronous callback function. That function will be called _after_ the function has returned.

Here's how to send messages asynchronously: [https://nodered.org/docs/writing-functions#sending-messages-asynchronously](https://nodered.org/docs/writing-functions#sending-messages-asynchronously)

---

<div class="post-metadata">

### Author: ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)
#### Post date: [16 October 2018 14:20 UTC](https://discourse.nodered.org/t/not-getting-msg-from-function-node/4029/3 "2018-10-16T14:20:17Z")

</div>

Thank you, that was the issue.
