zx icon indicating copy to clipboard operation
zx copied to clipboard

Support for dotenv (`.env`) files

Open joselcvarela opened this issue 3 years ago • 5 comments

Expected Behavior

Support for dotenv files

Actual Behavior

Do not support dotenv files

Motivation

These files are specially useful in order to avoid to type same environment variables multiple times. In some cases, it also can be helpful to track them with a version controller.

That being said, zx could support this behaviour because:

  • we may need these .env files in any folder
  • we do not want to add package.json and install additional packages
  • fetching data from remote or any other operation might need credentials that could be stored in these .env file

Related

https://github.com/google/zx/pull/327

joselcvarela avatar Jun 28 '22 20:06 joselcvarela

I think we should make this issue in a more generic way, not just loading dotenv file. I suggest doing it similar to the way docker did: load env variables from .config file. For example: zx --env-file=/foo/bar/cred.config script.mjs

nhonx avatar Aug 11 '22 19:08 nhonx

You can use this

require('dotenv').config({ path: __dirname+'/.env' });

Cyberarray avatar Sep 23 '22 06:09 Cyberarray

can i work on this feature?

meanii avatar Mar 13 '23 17:03 meanii

latest node support process.loadEnvFile(envVarsPath); out of the box

ziimakc avatar Apr 16 '24 22:04 ziimakc