Can a node-red flow from a node-red project discover the path to the directory where the project is checked out?
I want my flow to call a custom shell script using the exec node and I would prefer to store the shell skript in the same git repository as the node-red project that uses it.
Right now I have the exec node configured to call /home/pi/.node-red/projects/nodered-MyProject/skripts/send_sms.sh, but if I were to migrate the project in the future to a different computer that is not a Raspberry Pi, the /home/pi/.node-red/projects/nodered-MyProject part of the path needs to be replaced with the directory where the git project is checked out on the new computer. Can this part be replaced dynamically with the correct directory?
Yes, I could adjust environment variables, or I could just copy the skript into a directory on the PATH, or modify the PATH for the node-red process.
But I want to avoid this additional step if possible: I am creating my home automation and I want to prepare for a migration at some point in the future when I have forgotten about all the additional steps that are required for my setup after checking out the project and one npm install. I want to minimize the additional steps.
node-red already knows the location of that directory. It loads the flows from there. The web interface detects when I manually change files there. I want to know if this information can be accessed from a node in the flow.
Just brainstorming here, but can’t you set a global function in the same way as you would when making JavaScript libraries available to function nodes (in the settings file), and have that function resolve the path? Then you can retrieve that location via a function node to pass to the correct output.
Might not be exactly right because I collect some of the data separately in uibuilder and I have a utility function that delves into objects that may or may not exist.
Based on the code that I found in your node I have created a new node node-red-contrib-projectdir that extracts the information from node-red settings and inserts it into msg in the flow: node-red-contrib-projectdir. The palette manager has not yet picked it up but it can be installed already with npm.