process.env.HOMEPATH for userDir

129 views
Skip to first unread message

Guilherme Francescon Cittolin

unread,
Jun 28, 2016, 10:10:56 PM6/28/16
to Node-RED
Hi everybody,

I've installed node-red on my secondary D: drive for some tests and, when running it from this secondary disk, Node-RED creates a "\User\<username>" folder into this drive (e.g. D:\User\Guilherme, whereas Windows is installed on C:\). Taking a look, the default userDir is evaluated from the following expression:

process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE

Here, HOME is not defined (as on Windows, normally) and HOMEPATH is:

HOMEPATH=\Users\Guilherme

So, the node-red folder is actually depending on the working directory of node's executable, which may not always be in the same drive as Windos and the user profile.

There's a HOMEDRIVE env. variable (at least here in my machine) that we could join or concat here, or even drop it out completely, as the USERPROFILE variable correctly contains the drive letter. Another possibility would be to switch to APPDATA or LOCALAPPDATA, where most Windows application store their data.

What do you think? Should I open an issue and/or PR on gitHub?

Thanks!

Julian Knight

unread,
Jun 29, 2016, 3:59:58 AM6/29/16
to Node-RED
Good catch. I would think that userprofile should be first? Of course, that might break other assumptions?

Dave C-J

unread,
Jun 29, 2016, 5:17:14 AM6/29/16
to node...@googlegroups.com

Guilherme Francescon Cittolin

unread,
Jun 29, 2016, 12:37:35 PM6/29/16
to Node-RED
Well, from the link you posted, I tend to say the "most standard" way would be to use LOCALAPPDATA\Node-RED, with fallback to APPDATA\Node-RED. At least here in my Windows machine, the vast majority of apps store their data there. But this could break existing installations on update, or other issues I'm not aware of.

If we change to (LOCAL)APPDATA, we could check if the HOMEPATH\.node-red or USERPROFILE\.node-red exists (case of an upgraded installation), and if not, then create and use the (LOCAL)APPDATA\Node-RED (case of a new install). But this could confuse some users when searching where Node-RED stores its data. There's a tradeoff usability x standards here we may need to choose a side.

At least, we could change it to:
process.env.HOME || process.env.USERPROFILE


What do you think?

Dave C-J

unread,
Jun 29, 2016, 1:50:21 PM6/29/16
to node...@googlegroups.com
I still think the USERPROFILE is probably the right answer for us... as all the additional node docs say to change directory to the .node-red directory in your home directory - and moving those files off to APPDATA would mean extra docs just for windows users...

However even just moving to USERPROFILE we need to be slightly careful to check for existing installs as you say... and if there is something in HOMEPATH then to honour that - but to create new in USERPROFILE. This needs doing in both red.js and localfilesystem.js

Julian Knight

unread,
Jun 29, 2016, 2:17:40 PM6/29/16
to Node-RED
Even on Windows, using USERPROFILE is common as I expected and confirmed with a quick check. There are plenty of folders with leading dots in there for software that is cross-platform. That includes .node-red, .node-gyp, .nuget, .freemind, .gimp-2.8, some oracle stuff, ssh, etc.
Reply all
Reply to author
Forward
0 new messages