Is the documention right on node context?

I'm writing a function node that needs to use the node context but on https://nodered.org/docs/creating-nodes/context
it shows

// Access the node's context object
var context = this.context();

var count = context.get('count') || 0;
count += 1;
context.set('count',count);
//added by me to return the count
msg.payload = context.get('count');
return msg

But unless I comment out the 1st line I get an error when I use this example
#Confused :frowning:

You are looking at the docs on creating custom nodes. In that case, that first line is required.

The documentation for using Context in the Function node is here and doesn't require that first line as context is already defined.

1 Like

That explains things! :slight_smile:

I just clicked on 1st result instead of the 2nd one

image