Accessing global variables from a custom node

Hello,
i recently managed to create my own node but unfortunately i can't access my global variables in the JavaScript Code of the node. I tried it like this: global.get("name")
As soon as i use it in Node-RED i get the following Error:
"TypeError: global.get is not a function"

Does somebody know how to do it in the right way?
Thank you in advance!

As per the docs? https://nodered.org/docs/creating-nodes/context

Thats my code:
module.exports = function(RED) {
function test11(config) {
RED.nodes.createNode(this,config);
var context = this.context();
var globalContext = this.context().global;
var node = this;
this.on('input', function(msg) {

    var outMsg = {};
	
	var path = msg.path;
	var iteration = msg.iteration;

	outMsg.headers = {};
	outMsg.headers['Authorization'] = 'Basic '+ global.get("encodedWithName");

What am I doing wrong ?

you name the global context globalContext not global. So you need globalContext.get("encodedWithName")

When sharing code on the forum, please follow the advice in this post: How to share code or flow json

Thank you very much!

thanks for the advice

for my case it is saying "ReferenceError: globalContext is not defined"

Post the function that shows this.

It is remarkable how often asking a question results in apparent solution of the problem without any further feedback from the original poster.

3 Likes