You can add the packages inside the addon configuration.
### Option: `system_packages`
Allows you to specify additional [Alpine packages](https://pkgs.alpinelinux.org/packages) to be installed to your Node-RED setup (e.g., `g++` . `make` , `ffmpeg` ).
**Note** : *Adding many packages will result in a longer start-up time for the add-on.*
### Option: `npm_packages`
Allows you to specify additional [NPM packages](https://www.npmjs.com/) or [Node-RED nodes](https://flows.nodered.org/?type=node&num_pages=1) to be installed to your Node-RED setup (e.g., `node-red-dashboard` , `node-red-contrib-ccu` ).
**Note** : *Adding many packages will result in a longer start-up time for the add-on.*
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/- - Not found
npm ERR! 404
npm ERR! 404 '-@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-10-25T20_48_50_397Z-debug.log
[22:48:50] FATAL: Failed installing npm package -
[cont-init.d] user.sh: exited 1.
[cont-finish.d] executing container finish scripts...
[cont-finish.d] 99-message.sh: executing...
-----------------------------------------------------------
Oops! Something went wrong.
We are so sorry, but something went terribly wrong when
starting or running this add-on.
Be sure to check the log above, line by line, for hints.
-----------------------------------------------------------
[cont-finish.d] 99-message.sh: exited 0.
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
Then you can use MD5 in your function nodes like this:
let md5 = global.get("md5");
let myHash = md5("blah");
Details on functionGlobalContext can be found here: Writing Functions : Node-RED
These docs also contain another option (functionExternalModules) which also seems to work, if enabled through settings.js.
In my experience this is not working. I can’t add the packages to the list of packages and use it, it says the package does not exists.
Also, it is very inefficient because it install them on every start, which is IMO a waste
out of curiosity: why you cannot add those packages using pallete? I always do that this way and never had problems.
Is it something unavailable through pallete?
You are talking about the palette, right?
Imagine that you need to hash some string right within a complex function node. If you install an MD5 contrib node through the palette you cannot use the MD5 function within the JS of a function node. You can only use MD5 as a dedicated node that acts on the payloads of messages.
But if you go the way described above you can use the new function right within your code.
MD5 is only an example here. It could be any function that is not available in native JS but available as a Node.js package.
Yes, I have activated that option too and it works.
But I much prefer the global version. And I don’t think that there is a performance penalty as this is probably only a question of scoping.
In my case I used it to install “graylog2” library so I can create a custom logger on node-red settings.js file. Now all my node-red logs are on a centralised place which is my logs-server.
// Configure the logging output
logging: {/* ... bla bla bla, the built it logging */},
graylog: {
level: 'debug',
handler(settings){
const graylog2 = require("graylog2");
const logger = new graylog2.graylog({
servers: [ { "host": "logs-server.home", port: 12201 } ],
facility: "node-red.js", // the facility for these log messages
});
return function gLogger(msg){
logger.log(msg)
}
}
}
},