You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How can I persist environment settings for one installed Node.js CLI? #5190
I’m new to Node.js and I’m trying to understand how people normally handle this. I keep Node.js and several tools in a portable directory on Windows. One tool reads XDG_CACHE_HOME to decide where to put its cache. If I set that variable in my Windows account, other programs that read it get the same value. And when I copy my portable setup to another PC, that setting stays behind.
I thought an .env file might work like a settings file for that particular installation of the tool. I could keep it somewhere in my portable directory, outside the package files that npm updates. What I haven’t found is how to tell Node once that those settings belong to that tool. I found --env-file, but whoever starts Node then has to know about the file. Sometimes that’s me in a terminal, and sometimes it’s another application starting the script directly from a different directory. Node.js documentation for --env-file
Is there an existing convention for keeping settings with an installed CLI so they apply in both cases? If this is usually handled outside Node.js, I’d be interested to know how people handle it there.
Related: nodejs/node#49514 discusses npm scripts. I’m also interested in the case where an application invokes node path/to/cli.mjs directly.
I used AI to help translate my question from Russian and reviewed the wording before posting.
Before You Submit
Searched for existing issues.
Reviewed the repository README and the linked guide to asking questions.
Activity