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

**URL:** <https://discourse.nodered.org/t/using-javascript-color-gradient-in-node-red-function-node/36037>\
**Category:** General\
**Created:** [17 November 2020 05:37 UTC](https://discourse.nodered.org/t/using-javascript-color-gradient-in-node-red-function-node/36037 "2020-11-17T05:37:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [17 November 2020 05:37 UTC](https://discourse.nodered.org/t/using-javascript-color-gradient-in-node-red-function-node/36037/1 "2020-11-17T05:37:46Z")

</div>

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

```auto
$ npm install javascript-color-gradient

```

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

```auto
    functionGlobalContext: {
        os:require('os'),
        i2c:require('i2c-bus'),
        gradient:require('javascript-color-gradient')
    },

```

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

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

theGradient.setMidpoint(100);
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...

```auto
[{"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":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [17 November 2020 05:46 UTC](https://discourse.nodered.org/t/using-javascript-color-gradient-in-node-red-function-node/36037/2 "2020-11-17T05:46:42Z")

</div>

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

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

```

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 December 2020 05:46 UTC](https://discourse.nodered.org/t/using-javascript-color-gradient-in-node-red-function-node/36037/3 "2020-12-01T05:46:44Z")

</div>

Closed on 1 December 2020 05:46 UTC

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