Hi all. I'm somewhat new to node.js and Node-Red, so please bear with me as I may be overlooking something obvious. I have some class definitions in a private npm module that I created. In my index.js file I use the following to define a class and export it.
class Phase {
//class definition here
};
export default Phase;
Then I published the module and installed it globally. I updated the settings.js file to require the module I created based on this documentation: Writing Functions : Node-RED
After that, I restart node-red and add the module into the function node under the setup tab. Then, I try to use the class definition as follows in my function node:
var class = global.get('helper); //helper is the name used in settings.js file
let test = new class.Phase();
When I run my flow I get the error:
"TypeError: class.Phase is not a constructor"
Any help resolving this would be greatly appreciated as I'm at a loss for how to resolve this issue. I'm assuming this is an issue with how I export the class definition. I've also tried exporting it using
I do have multiple classes defined that I wanted to put in the module. I tried using
module.exports = {
Phase
}
This still gave me the same error as before. I then tried just using
module.exports = Phase
This fixes the error about not being a constructor. However, now when I try to use my classes member functions they always return undefined. For reference, I previously had this class definition in a function node, so I know the class is working. I also took a look at @TotallyInformation repository and seem to be doing the same as him, other than using class instead of function. I made sure that I published the module and installed again globally after making changes. I also make sure that I restart node-red after making changes to the module. Any ideas as to why I can't call my member functions?
For example:
const Phase = global.get("helper");
let test = new Phase();
return test.numParams; //returns undefined, numParams is a getter in this class