How the get the current OS User?

I need to get the current OS user to be able to write a path variable. I have downloaded node-red-contrib-os but are still not getting the current username. I want to set a variable that gets the current username to set the path to the local Dropbox folder. This way I can deploy my flow in various computers and the path to Dropbox will be set automatically.

Any help would be greatly appreciated.

in Linux the user is usually available as an environment variable $USER

Thank you very much. Need to look into environment variables to see what else is there I can use.

You can also easily pass env variables into global variables in node-red's settings.js file. For my dev setup, I pass all env vars into a single _env global variable for convenience (not a good idea to do that on a live server for security reasons).

see - Using environment variables : Node-RED

You can also use HTML DOM Navigator Object via ui-template node, like this:

[{"id":"f6f2187d.f17ca8","type":"tab","label":"DOM Nav","disabled":false,"info":""},{"id":"d05119dc8fe4d1ce","type":"debug","z":"f6f2187d.f17ca8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":430,"y":140,"wires":[]},{"id":"86b5b0f9941207e8","type":"ui_template","z":"f6f2187d.f17ca8","group":"1ebfeecaaae0efae","name":"DOM Navigator","order":0,"width":0,"height":0,"format":"<script>\n    (function(scope){ \n     var os = navigator.appVersion + \" , \" + navigator.platform;\n     scope.send({payload:os });\n    })(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":260,"y":140,"wires":[["d05119dc8fe4d1ce"]]},{"id":"1ebfeecaaae0efae","type":"ui_group","name":"Group 1","tab":"a3d2f4fd.462a68","order":1,"disp":true,"width":6},{"id":"a3d2f4fd.462a68","type":"ui_tab","name":"DOM","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Not sure how that gets you the user running the Node-RED process

Thank you all. Used the $USER env variable and got it all working beautifully. Thank you so much. I just started with JavaScript and Node Red about two weeks ago and are having a blast learning. Starting to want more sophisticated things that are pushing me to learn deeper concepts. Working on simplifying my flow and getting the variables I need from a .json file stored in Dropbox. All working great now. Want to just commit changes to GitHub from my local computer and then have the remote computer just pull the changes to update my flows.
I am wondering, is there a way to have the remote computers pull the commits and start on their own?.

I am not sure what you mean. Does
git pull
node-red-restart
do what you want?

Yes, if logged onto the remote computer. I might not have access to it because of security reasons. I can have the remote computer communicate out and send me status messages but hoping for a way to keep updating my flows by having the remote computer auto update from time to time. Not a necessity. Just trying to see what it’s possible.

Well this is one way to do it ... Deploying Node-RED applications to devices using Balena · knolleary

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