I want to use a npm package in a node red function node. I have been using a NEST thermostat api in nodes code running on an intel edison and now I want to run the same code as part of a function node. I tried adding the packages into the blooms-settings file in my app. I googled this and it pointed me to the how to write functions page. As usual, too much terminology with too few examples. If I can't do this, then node red is almost a toy and adds little value for me.
Answer by knolleary (2799) | Oct 09, 2015 at 02:12 PM
Hi,
steps are:
add it to the dependencies section of your app's package.json file.
then, in your bluemix-settings.js file, add it to the functionGlobalContext
object:
functionGlobalContext: {
mymodule: require('the-module-you-want-to-add')
},
at which point, in your function node you can access the module as context.global.mymodule
The section of the docs that covers this is here: http://nodered.org/docs/writing-functions.html#global-context - with an example of adding the 'os' module.