Run npm modules inside node-red

898 views
Skip to first unread message

TridiumControls

unread,
Sep 26, 2016, 8:33:47 AM9/26/16
to Node-RED

Hi,

How would I go about running this inside node-red?

https://www.npmjs.com/package/nodbus

I have tried Installing the npm node that exposed npm modules as node-red nodes,

http://flows.nodered.org/node/node-red-contrib-npm

And can't get nodbus to work, can someone throw some light on this?

Thanks

Message has been deleted

Mark Setrem

unread,
Sep 26, 2016, 9:56:21 AM9/26/16
to Node-RED
If you want the npm module to be available in function nodes the method is explained in the documentation.
http://nodered.org/docs/writing-functions

The global context can also be pre-populated with objects when Node-RED starts. This is defined in the main settings.js file under the functionGlobalContext property.

For example, the built-in os module can be made available to, all functions:

functionGlobalContext: {
osModule:require('os')
}
at which point, the module can be referenced within a function as global.get('osModule').

Ben Hardill

unread,
Sep 26, 2016, 11:26:24 AM9/26/16
to Node-RED
While remarkably usefult the node-red-contrib-npm node can only be used with relatively trivial nodes

For somethings like modbus you can try the approach that Mark outlines to try it in a function node, but to get the most from it you will have to write your own node-red wrapper node.

The docs for this are on the node-red website.

Out of interest what are you trying to do that the existing modus node-red nodes don't do?

TridiumControls

unread,
Sep 26, 2016, 11:30:46 AM9/26/16
to Node-RED
Main reason I am using nodebus is because it supports float value out of the box, I have a energy meter that has float registers. I have used modbus-tcp from flows.nodered.org and I can read the registers, but the value is a float and needs to be converted, I did find this

https://www.npmjs.com/package/float-bits

I have installed it and now trying to use it to convert the data. But am having difficulty, how to wrap the function code and send it to the float-bits npm module and back.
Reply all
Reply to author
Forward
0 new messages