Instructions for modules through function node

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.

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

1 Like

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?

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

And with options:

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)


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

1 Like

Fantastic, thank you!

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