Global Variables Between Nodes

734 views
Skip to first unread message

Mathew Fleisch

unread,
Mar 13, 2017, 5:55:50 PM3/13/17
to Node-RED
Hello all,

I am relatively new to node-red and still learning the idiosyncrasies, so please be gentle. I am working on a project where I am developing my own nodes, to carry out custom functionality (integrating it with an existing tool/black-box). I want to be able to access data from a previous node, during configuration, before the whole flow is deployed. The first node should take in csv data and run a background process after the source is selected (which works fine). The next step/node in the sequence requires the configuration to change based on the first node's payload. I was first researching global variables but I couldn't access them within the node code itself, only within the UI. My only other thought is to write/read data to a temporary file between each node. Also, I am trying to avoid combining these two nodes into one, even though it would also be another way to maintain scope between the two "steps."  

Is this possible? Any suggestions in general?

Thanks,
Mathew

St...@nprowler.com

unread,
Mar 13, 2017, 7:14:22 PM3/13/17
to Node-RED

Dave C-J

unread,
Mar 13, 2017, 7:18:05 PM3/13/17
to node...@googlegroups.com
Do you really mean that you want the 2nd node config to depend on the 1st payload ? If so then just pass it as part of the msg between the nodes and act on("input", ... 
If you want the 2nd to share config with the first then as long as they really are always a pair.. then you could define them both in the same js / html files and share state within that.... But obviously you then have to handle the situation when you have more than one pair...

Mathew Fleisch

unread,
Mar 13, 2017, 7:45:11 PM3/13/17
to Node-RED
Hey Dave,

Thanks for the reply. The two nodes are always a pair and technically should be one node with multiple configuration states... However, the project requires two separate nodes (dictated by boss); so that's what i'm trying to do. Imagine the first node saving a csv file, and the second node requires the csv column headers to continue configuring the second node (before deploy). Node red should save the file within the first node and the second node should automatically pull in metadata about the file saved within the first node. This should all happen before the flow is deployed (the idea is to use node-red itself as the interface for this project). At the moment, my workaround is to set a localStorage variable during the first node configuration, and then check/load that variable within the second node, onEditPrepare(). 

Mathew Fleisch

unread,
Mar 13, 2017, 7:46:03 PM3/13/17
to Node-RED
Been all over the documentation, but I could not get the global context to work within my custom node... only within the UI itself. 

Dave C-J

unread,
Mar 13, 2017, 7:59:35 PM3/13/17
to node...@googlegroups.com
If they are defined in the same js file then you can set a shared variable outside the scope of each that is set by the first and read by the second.... But as I said you may then need to handle the case where there is more than one pair.

sent from phone
Reply all
Reply to author
Forward
0 new messages