# How the get the current OS User?

**URL:** <https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699>\
**Category:** General\
**Created:** [15 January 2022 14:04 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699 "2022-01-15T14:04:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)\
**Post date:** [15 January 2022 14:04 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/1 "2022-01-15T14:04:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 January 2022 14:08 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/2 "2022-01-15T14:08:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)\
**Post date:** [15 January 2022 18:14 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/3 "2022-01-15T18:14:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 January 2022 18:16 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/4 "2022-01-15T18:16:11Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 January 2022 18:59 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/5 "2022-01-15T18:59:04Z")

</div>

see - [Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables)

---

<div class="post-metadata">

**Author:** ![thejollypop](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thejollypop/32/36597_2.png) [@thejollypop](https://discourse.nodered.org/u/thejollypop)\
**Post date:** [15 January 2022 21:34 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/6 "2022-01-15T21:34:44Z")

</div>

You can also use [HTML DOM Navigator Object](https://w3schools.sinsixx.com/htmldom/dom_obj_navigator.asp.htm) via `ui-template` node, like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/47264a02b26a7fcdda5aa981d288136cccf6da92.png)

```auto
[{"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}]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 January 2022 09:59 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/7 "2022-01-16T09:59:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)\
**Post date:** [16 January 2022 13:17 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/8 "2022-01-16T13:17:43Z")

</div>

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?.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 January 2022 13:51 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/9 "2022-01-16T13:51:05Z")

</div>

> [@patofoto](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)\
**Post date:** [16 January 2022 16:06 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/10 "2022-01-16T16:06:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 January 2022 17:13 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/11 "2022-01-16T17:13:15Z")

</div>

Well this is one way to do it ... [Deploying Node-RED applications to devices using Balena · knolleary](https://knolleary.net/2018/09/27/deploying-node-red-applications-to-devices-using-balena/)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 March 2022 17:14 UTC](https://discourse.nodered.org/t/how-the-get-the-current-os-user/56699/12 "2022-03-17T17:14:14Z")

</div>

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