# Deconstructing an object

**URL:** <https://discourse.nodered.org/t/deconstructing-an-object/44143>\
**Category:** Developing Nodes\
**Created:** [14 April 2021 08:13 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143 "2021-04-14T08:13:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [14 April 2021 08:13 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/1 "2021-04-14T08:13:33Z")

</div>

How would i make a custom node that recives some  
`{ name: "Hello" }`  
and gives back only the name. Like msg.payload.name  
I tried writing it like that but it gives back undefined

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 April 2021 08:31 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/2 "2021-04-14T08:31:11Z")

</div>

Please read the node red docs on [creating nodes](https://nodered.org/docs/creating-nodes/), that will give you a good introduction on how to do it.  
When you have read and understood that, if it still doesn't work then put your node in a repository on github and give us a link to it, then we can look at it and install it if we wish. Do not publish it to npm though.

---

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [14 April 2021 08:56 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/3 "2021-04-14T08:56:24Z")

</div>

Understood. 1 more question tho. Can i somehow make `global.set("LeadPump", msg.payload.value);`  
inside my javascript file of custom node?

---

<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:** [14 April 2021 09:10 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/4 "2021-04-14T09:10:18Z")

</div>

Why are you updating global context from inside a custom node?

This can (will) lead to issues with peoples installation of node-red.

Unless there is a very good reason - do NOT update flow or global context from your custom node - instead, pass the values out of your node and the user can set flow/global context.

---

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [14 April 2021 09:20 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/5 "2021-04-14T09:20:56Z")

</div>

Im just testing something and need this to make it work. This wont be published on node-red. Just a practice.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 April 2021 10:37 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/6 "2021-04-14T10:37:13Z")

</div>

> [@jake123](#):
>
> Im just testing something

In that case test it and see what happens.

---

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [14 April 2021 11:17 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/7 "2021-04-14T11:17:27Z")

</div>

dont know how to give set the global context  
should be like this `let globalContext = this.context().global; globalContext.set("Pressure1", msg.payload)`

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [14 April 2021 11:35 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/8 "2021-04-14T11:35:42Z")

</div>

You can always learn a lot of basic things by looking at existing nodes from other developers. E.g. [here](https://github.com/DeanCording/node-red-contrib-config/blob/master/config.js#L41).

---

<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:** [13 June 2021 11:35 UTC](https://discourse.nodered.org/t/deconstructing-an-object/44143/9 "2021-06-13T11:35:47Z")

</div>

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