I followed the online tutorial to create your first node. It worked exactly as expected.
I then tried to create my own node and everything goes well until I try to use it within node-red. The only difference between the example and my code is, that I have a dependency on sensit-payload.
When I use the node, I get the following error:
[error] [sensit-decoder:c6cbc5fe.014f18] Error: Could not locate the bindings file. Tried:.....
When I create a function within node-red with the sam function code in my node js file, It works fine, with no errors.
Hi @TotallyInformation. I moved the require to outside the module.exports, but then the node won't register.
When I place it after RED.nodes.createNode(), I get no errors, but also no response:
module.exports = function(RED) {
function SensitDecoderNode(config) {
RED.nodes.createNode(this,config);
const sensitPayload = require('sensit-payload');
var node = this;
node.on('input', function(msg) {
msg.payload = sensitPayload.parse(msg.payload);
node.send(msg);
});
}
RED.nodes.registerType("sensit-decoder",SensitDecoderNode);
}
When I remove it completely, as expected, I get "ReferenceError: sensitPayload is not defined" inside node-red debug.
When I use the sensit-payload package within a function inside node-red, it works fine.
I am definitely not an expert developer and this is my first attempt at trying to write a node, so it is a learning curve for me.
The above should work as long as sensitPayload.parse(msg.payload) is valid.
As I said before, I think this is an issue with 'sensit-payload'.
If you look at my node-red-contrib-uibuilder node, especially the v2 branch you should see that I've used the structure above and it works just fine.
I would also recommend using a code editor with ESLint or JSLint to help you with the layout of your code and avoid mixing quote types as the above code does (' and "). While this isn't an error, it is harder to read which makes identifying errors harder.
A quick look at the code shows me that the bindings file is a C library that installing the package should automatically create for you.
I'm thinking that you either didn't completely install the package or it is installed in the wrong place.
Does your node's package.json include a reference to sensit-payload and did you run npm install to get it installed? Did you get any errors from the compilation?
Might be best to delete the package folder and start again.
Hi @TotallyInformation. After I replied earlier, I actually went back to my nodered directory and did a manual install of sensit-payload via npm. After that the node worked as expected.
There is a reference in the package.json, but I suspect somewhere along the line, the package did not install properly.