Using 'javascript-color-gradient' in node red function node?

I installed the gradient module I want to use...

$ npm install javascript-color-gradient

I set the module in settings.js file...

    functionGlobalContext: {

Restart NR, then I try use same in a function node...

const YELLOW = '#FFFF00',
      BLUE = '#0000FF',
      RED = '#FF0000',
      GREEN = '#008000';
var theGradient = global.get('gradient');

theGradient.setGradient(BLUE, GREEN, YELLOW, RED);

But I get an error stating that 'setMidpoint' is not function? It definitely is in the module.

Sample flow...

[{"id":"61ba5336.7bee9c","type":"inject","z":"fe68c827.8d72","name":"Test","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":320,"wires":[["843ec91f.5c2d3"]]},{"id":"843ec91f.5c2d3","type":"function","z":"fe68c827.8d72","name":"Test","func":"const YELLOW = '#FFFF00',\n      BLUE = '#0000FF',\n      RED = '#FF0000',\n      GREEN = '#008000';\n      \nvar theGradient = global.get('gradient');\n\ntheGradient.setMidpoint(100);\ntheGradient.setGradient(BLUE, GREEN, YELLOW, RED);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":230,"y":320,"wires":[[]]}]

Nuts... I looked at it a few minutes later and realized I was not calling the constructor right, it should be such...

var GRADIENT = global.get('gradient');
var theGradient = new GRADIENT();

The javascript module is a simple class, that has to be initiated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.