Load external modules in the function node

Hi, How can I load or use external libraries to a function node?
I wanna use the "influx" node to my function. I read a lot of tutorials about it seems like it never worked to me. Hope you guys can help me.

This is my settings.js config:
image

And as per documentation, you can use this in function node via:

var INFLUX = global.get("influx")
var influxDB = new INFLUX.influxDB(influx_config)
influxDB.writePoints(msg.payload.data)
return msg;

But I have error:
image

Am I missing something?

Thanks and Regards,

That would be a correct approach (at least one way)
Therefore, the error you are getting, might be more about how the use of the module/the module it's self

maybe its :man_shrugging:

const INFLUX = global.get("influx")
const influxDB = new INFLUX(influx_config)
influxDB.writePoints(msg.payload.data)
return msg;

Given the error, it would suggest you are trying to instantiate something that isn't a class - I don't use influx, so don't know its module (or exports)

Just checking that you know there is a widely used contrib node for accessing influxdb.

1 Like

Hi,
I think it's working now I just need to restar the nodered.

Thanks!

Hi Collin,
Thanks for checking in, yes I know that, I actually using it for quite some time. How ever you cannot pass dynamically the name of the database in msg.db, you have to configure it on the influx node, in my case I need to pass it dynamically so I need to have customized function for it

Regards

Do you actually need to change it at run time, or would specifying the db via environment variable or in a subflow be good enough?

I need to specify the DB outside the nodered platform. I don't want the user to open my nodered editor, so I need to create my own UI for this, and pass this parameter in nodered via runtime.
I actually tried the subflow environment and pass it to influx node config, but seems like there is a problem. I don't have choice but to do like this.

Cheers,

In that case you could use an environment variable.

I actually tried that.

and set the influx node to be like this:
image

and set environment:
image

but gives me the ff error when using the subflow:
image

I didn't mean in a subflow. You said you wanted to setup the db outside node-red, so set an environment variable and use it node-red.

How can I use that environment variable to input it in influx node?

The same was as you did in a subflow that did not work, but not in a subflow. I imagine the reason it did not work was because it was in a subflow, are you using the latest version of node-red?

I suspect that the reason you had trouble using the node in a subflow may be down to this.

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