# Instructions for modules through function node

**URL:** https://discourse.nodered.org/t/instructions-for-modules-through-function-node/64967
**Category:** General
**Tags:** function-node
**Created:** [11 July 2022 18:28 UTC](https://discourse.nodered.org/t/instructions-for-modules-through-function-node/64967 "2022-07-11T18:28:31Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Kylespamaccoun7](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kylespamaccoun7/32/64229_2.png) [@Kylespamaccoun7](https://discourse.nodered.org/u/Kylespamaccoun7)
#### Post date: [11 July 2022 18:28 UTC](https://discourse.nodered.org/t/instructions-for-modules-through-function-node/64967/1 "2022-07-11T18:28:31Z")

</div>

I recently updated to the version that allows modules to be added from the function node. I am trying to test this out.

I have the module installed.

Is there documentation available explaining what to do next? I can't find a 'hello world' type guide on how to use the function node to interact with module?

My first thought was to use global variables. I would assign what I want module the module to use to a global variable, named according to what the library looks for? Then run it by injecting a blank message into the function node containing the module. The output would be visible as a global variable too. Is this right?

I honestly appreciate any help understanding this, or any resource/documentation I can learn from.

---

<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: [11 July 2022 20:28 UTC](https://discourse.nodered.org/t/instructions-for-modules-through-function-node/64967/2 "2022-07-11T20:28:42Z")

</div>

> [@Kylespamaccoun7](#):
>
> I can't find a 'hello world' type guide on how to use the function node to interact with module?

Because each npm module has thier own way of exporting functionality.

If you want a simple example, then try it out. Add `cowsay` and call its `say` function as instructed in the `cowsay` readme

You should get...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b45f6f4ac67771a826f24f68fd64d4c4853d9ba5.png)

---

<div class="post-metadata">

### Author: ![Kylespamaccoun7](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kylespamaccoun7/32/64229_2.png) [@Kylespamaccoun7](https://discourse.nodered.org/u/Kylespamaccoun7)
#### Post date: [24 July 2022 17:54 UTC](https://discourse.nodered.org/t/instructions-for-modules-through-function-node/64967/3 "2022-07-24T17:54:34Z")

</div>

Hi, thanks for helping me out and sorry for the slow response. Managing hobbies on top of a work and a household is like.. crazy. And I dont even have kids...

I will download cowsay and test it out.

I'm struggling with the basic level of understanding though. It sounds really simple at its core i think?

1. get a module
2. identify a whatever function we want to use.
3. identify what information the function requires.
4. Return the payload or however its assigned.

Im on mobile so i might have missed the formatting but is the gist of this correct?

ModuleName.function(necessary input){option 1: value, option 2: value, options 3: value}`

And was your function node something like this then?

```auto
msg.payload = cowsay.say('hi');
return msg.payload

```

And with options:

```auto
msg.payload = cowsay.say("hi"){
    Text: "i'm a module",
    e : "oO",
    T : "U "
};
return msg.payload;
``
```

---

<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: [24 July 2022 18:07 UTC](https://discourse.nodered.org/t/instructions-for-modules-through-function-node/64967/4 "2022-07-24T18:07:18Z")

</div>

> [@Kylespamaccoun7](#):
>
> And with options:
> 
> ```auto
> msg.payload = cowsay.say("hi"){
> Text: "i'm a module",
> e : "oO",
> T : "U "
> };
> return msg.payload;
> 
> ```

That would not work as the object is outside of the function parenthesis and you must always return the `msg` object (not the payload)

  

> [@Kylespamaccoun7](#):
>
> 1. get a module
> 2. identify a whatever function we want to use.
> 3. identify what information the function requires.
> 4. Return the payload or however its assigned.
> 
> Im on mobile so i might have missed the formatting but is the gist of this correct

Pretty much - so long as you really mean...

1. Identify a module that does what I need
  - Find it in npm
  - copy it's name as listed in NPM
  - Add the module as named in the function setup tab modules list

2. identify whatever function(s) we want to use & the parameters they require, then call it/them as prescribed by the modules instruction/docs
3. Assign the result to `msg.payload`
4. Return the `msg`

* * *

Bottom line, just give it a go

---

<div class="post-metadata">

### Author: ![Kylespamaccoun7](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kylespamaccoun7/32/64229_2.png) [@Kylespamaccoun7](https://discourse.nodered.org/u/Kylespamaccoun7)
#### Post date: [24 July 2022 18:12 UTC](https://discourse.nodered.org/t/instructions-for-modules-through-function-node/64967/5 "2022-07-24T18:12:26Z")

</div>

Fantastic, thank you!

---

<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: [22 September 2022 18:13 UTC](https://discourse.nodered.org/t/instructions-for-modules-through-function-node/64967/6 "2022-09-22T18:13:20Z")

</div>

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