Reputation: 164
I am taking my first steps in node.js/node-RED and need to do http requests (GET, POST with and without xml payload) from a node component so I figured that xmlhttprequest is my best option. I have npm-installed it. Actually installed it in ~/.node-red/node_modules and /usr/local/lib/node_modules but each time I launch node-RED it does not activate my node component with the following error:
Welcome to Node-RED
===================
7 Aug 09:05:20 - [info] Node-RED version: v0.17.5
7 Aug 09:05:20 - [info] Node.js version: v6.11.2
7 Aug 09:05:20 - [info] Darwin 16.7.0 x64 LE
7 Aug 09:05:20 - [info] Loading palette nodes
7 Aug 09:05:21 - [warn] ------------------------------------------------------
7 Aug 09:05:21 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
7 Aug 09:05:21 - [warn] [synaptiq-solar] Error: Cannot find module 'xmlhttprequest'
7 Aug 09:05:21 - [warn] ------------------------------------------------------
7 Aug 09:05:21 - [info] Settings file : /Users/rudi/.node-red/settings.js
7 Aug 09:05:21 - [info] User directory : /Users/rudi/.node-red
7 Aug 09:05:21 - [info] Flows file : /Users/rudi/.node-red/flows_Rudi.local.json
7 Aug 09:05:21 - [info] Server now running at http://127.0.0.1:1880/
7 Aug 09:05:21 - [info] Waiting for missing types to be registered:
7 Aug 09:05:21 - [info] - synaptiq-solar
The name of my component is synaptiq-solar and its code starts with requiring the xmlhttprequest component like this:
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
Also, my package.json has a dependency section referring to xmlhttprequest as you can see below:
{
"name": "synaptiq-solar",
"version": "0.0.1",
"description": "Just playing around, learning how to create a custom node",
"dependencies": {
"xmlhttprequest": "1.8.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"node-red": {
"nodes": {
"synaptiq-solar": "synaptiq-solar.js"
}
},
"author": "Smappee n.v.",
"license": "ISC"
}
So what am I doing wrong? Should I install the xmlhttprequest component in some other location? Is there another lib directory that node-RED is looking to find dependend components?
Upvotes: 0
Views: 1820
Reputation: 10117
If a custom node has an external dependency, it should declare it within its package.json
file so that they get installed alongside your custom module.
If you have created this as a "local" node (with just a .js
and .html
file in the nodes
directory and no package.json
), you should move over to creating it as a module.
The documentation includes a guide on properly packaging your node: https://nodered.org/docs/creating-nodes/packaging
Upvotes: 2