New to node-red, new to node.js - please forgive (and correct) newbie errors.
My node-red is installed on Linux, following directions from various node-red web pages. All working well. I read directions for installing a node.js module, that it has to be a non-global install in the directory ~/.node-red. Did that installation (for "flipacoin"), inspected the results, looks good as far as I can tell.
Tweaked the node-red "settings.js" file to include the line "flip:require('flip')", emulating other commented lines in the otherwise empty "functionGlobalContext" stanza. When attempting to start node-red, it fails to parse the settings file.
Can someone point me at information to allow me to get access to installed node.js functions, so that I can use them in node-red functions? Thanks in advance.
Welcome to the forum @Don
Possibly you have a small error in your settings, possible a comma misplaced for example. If you can't see it then copy/paste a few lines around the change you made so we can have a look. For how to post code and flows so they appear correctly here see this post - How to share code or flow json
// The following property can be used to seed Global Context with predefined
// values. This allows extra node modules to be made available with the
// Function node.
// For example,
// functionGlobalContext: { os:require('os') }
// can be accessed in a function block as:
// global.get("os")
functionGlobalContext: {
flip:require('flip')
// os:require('os'),
// jfive:require("johnny-five"),
// j5board:require("johnny-five").Board({repl:false})
},
And here's a peek at the contents of my ~/.node-red directory:
Colin, thanks for your help: when I changed the require statement, it worked. Unfortunately, I need the random true/false as part of additional logic, so I elected not to install & use that node.
While I have your attention, I am not so clear on how to get access to the 'flip' function from inside a node-red function node. Can you point me to an example?
Yes, I need it in a function node. I can do it with Math.random, but was trying to learn how to incorporate an npm module in general. Next time the problem won't be as simple as a random Boolean! But this solves the problem for now, thanks!
If you want to us flipacoin then in the function you should be able to say let flipacoin = global.get("flipacoin")
and then use flipacoin. I don't know that module so can't say exactly how.