Skip to content

Instantly share code, notes, and snippets.

@juggledad
juggledad / README.md
Last active July 12, 2019 12:06
EXAMPLE - using an external javascript in a function node

This example show how to use an eternal NPM javascript in a function node. This example uses tinycolor.js to test an RGB color to see if it is 'light' or 'dark'.

** Setup **

  1. Go to the node-red directory
  • cd .node-red
  1. Install tinycolor.js
  • npm install tinycolor2.js
  1. Backup your settings file incase something goes wrong.
  • cp settings.js settings.bkup
  1. Edit settings.js and find the section functionGlobalContext: { it should look like this
@juggledad
juggledad / README.md
Last active June 20, 2020 09:29
Using environmental variables (system or user defined)

Environmental variables (enter ‘env’ in a terminal to see which can be used) can be accessed by adding:

env: process.env

to the ‘functionGlobalContext:’ section of the settings.js file. Once entered you can access them in any node that has a text field (a/z) or in a function node.

SPECIAL CASES: If you want to use HOSTNAME or declare your own environmental variable, you must make an additional change to the settings.js file. Add the following lines just before the line ‘module.exports = {‘: