Trying to get 'require' to work but no result

I am trying to get a third-party package to work. I first tried the example 'os', and I got it functional.

Now I am trying to get the package 'node-dsmr' to function in a similar way.
I installed the package in ~/.node-red as it says in the manual, with command npm install node-dsmr.

Then I changed te settings.js

As I only need the parser, I should point to the parser.js file according to this site:

After restart node-red, I made a function node that has the added package defined,

But when I started to run the function node I get errors,

afbeelding

I checked the folder and the file is really there.

Can anyone tell me what I did wrong?

You don't need it in both places, only one or the other.

If you require it in settings.js, you have to use const xxxx = global.get('xxxx') in your function code.

If you apply it to the function node, you don't need to get it. It will just be available.

@TotallyInformation , sorry I don't know what you mean by both places.....

You've put it in settings.js and in the startup of your function node.

Hi @henkkas

You are mixing up the two different ways it is possible to add additional modules to the Function node.

Option 1:
edit your settings file as you have done and use const dsmrParser = global.get("dsmrParser")

Option 2:
Do not edit settings.js. Add the module to the 'Setup' tab of the Function node. If you do that, you have to provide the npm module name - node-dsmr - the runtime will then ensure it is installed and loaded. I'm not 100% sure if it'll work doing node-dsmr/lib/parser.. you may have to require node-dsmr and then 'explore' the object that returns from find the parser bit of it.

@knolleary , Thank you. Option 1 is working for me, but option 2 I can't get to work.

As I like option 1 better, I settle for that.

The package seems to be a 'function' object.
The 'os' package was a 'data' object. Maybe that's the reason ???

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