Question about context variables

Please can someone explain to me the difference between these two approaches to node scoped context?

if ( !context.count ) context.count=0;
context.count++;
node.warn( context.count );

or

var Count = node.get( "count" ) || 0;
Count++;
node.warn( Count );
node.set( "count" , Count );

The first seems much simpler but I have been unable to find it documented anywhere.

Thank you
Graham

Use context.get to ensure future compatibility if you ever decide to switch to file/db backed context.

In other words, context.count would never be written to file (or database)

Reference: Writing Functions : Node-RED

1 Like

Thank you.

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