Skip to content

How can I persist environment settings for one installed Node.js CLI? #5190

Backlog

Description

@Sonicegorsan

Node.js Version

v24.15.0

NPM Version

11.12.1

Operating System

Windows 10 x64 (build 19045)

Subsystem

process

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions