Access global and/or flow context from a GLOBAL HOOK?

Hi !
Is there any way to access the global or the flow context in which an activated (and working !) global hook will be fired (for ex. "onSend") ?

All tries (global.get/set,, context().global.set/get,, this.context ........) did not work. Any solution or any good idea ?
Kind regards

As I asked in your other thread:

sorry - that I've not answered your question.

It's reduced to "const sqlite3 = require('sqlite3').verbose();" - included in a custom node (which works fine meanwhile).

My second question - about accessing context data (global and/or flow) should also been done inside this custom node from which I'm activating hooks (onSend, onCompleted).

Ok, I've moved this to the #developing-nodes section.

Can I first ask why do you need access to global context? Your own node will have its own closure (for variables that live the life of the runtime) so access to context is not really needed. And imo, not a great idea.

What I would like to do is to build a unique identifier for each running flow each time, to write a log-file with all (for me) required information. To cat all information / events - within one running flow each time it will be processed - together (in the logging-file) I will access this unique identifier from all nodes within one flow within one run/process - so my idea is, that accessing this identifier via the hooks via the global/flow context will be the best way. I don't want to modify any node / any flow - thats the reason I'll use the Hook-Events.

Context can only be accessed via a node in the flow; we don't provide a way to access it directly in a plugin - largely because it hasn't been needed.

Do you need to access this information in multiple places in the code? Or is it entirely within your own hooks? If the latter, why use context when you can just store the information locally yourself?

Since the hooks are executed within the nodes in a flow (on the server), I assumed that the "outer context" was also available.

I have integrated several functions within the node that registers the hooks, which are then called by all nodes and create and determine the "UnifiedID", as well as details about the respective node and the assignment to the respective flow (via the "start" file determined) and so process the logging of the necessary data in a SQLITE database.

Of course, I could also register the ID via the SQLITE database and then read out this data in each node, but for me this does not appear to be performant enough and poses imo too many risks in the processes (DB lock, etc.).

Hence the consideration of working with memory variables that are also reset when Node-Red is aborted and restarted.

I hope my thoughts have become understandable and clear. Thank you for your support and the time you are spending.

I could still find a solution. I use the option of global variables provided in Node.js in the standard and initialize them in the "onSend" hook. This means that they can be used for all nodes in a flow. I use the ID of the flow as a name of the variable, which ensures uniqueness. Maybe someone else can do something with this. Greetings.

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