google / zx

A tool for writing better scripts
https://google.github.io/zx/
Apache License 2.0
43.03k stars 1.1k forks source link

Support for dotenv (`.env`) files #461

Open joselcvarela opened 2 years ago

joselcvarela commented 2 years ago

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:

Related

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

nhonx commented 2 years ago

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

Cyberarray commented 2 years ago

You can use this

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

meanii commented 1 year ago

can i work on this feature?

ziimakc commented 6 months ago

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

Anonymous961 commented 5 months ago

Can you please close this issue? image