Git Product home page Git Product logo

dotenv-cli's Introduction

dotenv-cli

Installing

NPM

$ npm install -g dotenv-cli

Yarn

$ yarn global add dotenv-cli

Usage

$ dotenv <command with arguments>

This will load the variables from the .env file in the current working directory and then run the command (using the new set of environment variables).

Custom .env files

Another .env file could be specified using the -e flag:

$ dotenv -e .env2 <command with arguments>

Multiple .env files can be specified, and will be processed in order:

$ dotenv -e .env3 -e .env4 <command with arguments>

Cascading env variables

Some applications load from .env, .env.local, .env.development and .env.development.local (see #37 for more information). dotenv-cli supports this using the -c flag for just .env and .env.local and -c development for the ones above.

Check env variable

If you want to check the value of an environment variable, use the -p flag

$ dotenv -p NODE_ENV

Flags to the underlying command

If you want to pass flags to the inner command use -- after all the flags to dotenv-cli.

E.g. the following command without dotenv-cli:

mvn exec:java -Dexec.args="-g -f"

will become the following command with dotenv-cli:

$ dotenv -- mvn exec:java -Dexec.args="-g -f"

or in case the env file is at .my-env

$ dotenv -e .my-env -- mvn exec:java -Dexec.args="-g -f"

Variable expansion

We support expanding env variables inside .env files (See dotenv-expand npm package for more information)

For example:

IP=127.0.0.1
PORT=1234
APP_URL=http://${IP}:${PORT}

Using the above example .env file, process.env.APP_URL would be http://127.0.0.1:1234.

Variable expansion in the command

If your .env file looks like:

SAY_HI=hello!

you might expect dotenv echo "$SAY_HI" to display hello!. In fact, this is not what happens: your shell will first interpret your command before passing it to dotenv-cli, so if SAY_HI envvar is set to "", the command will be expanded into dotenv echo: that's why dotenv-cli cannot make the expansion you expect.

One possible way to get the desired result is:

$ dotenv -- bash -c 'echo "$SAY_HI"'

In bash, everything between ' is not interpreted but passed as is. Since $SAY_HI is inside '' brackets, it's passed as a string literal.

Therefore, dotenv-cli will start a child process bash -c 'echo "$SAY_HI"' with the env variable SAY_HI set correctly which means bash will run echo "$SAY_HI" in the right environment which will print correctly hello

Debugging

You can add the --debug flag to output the .env files that would be processed and exit.

License

MIT

dotenv-cli's People

Contributors

entropitor avatar plashenkov avatar dependabot[bot] avatar davecardwell avatar andyburke avatar ericrallen avatar aymericbouzy avatar christophgysin avatar forivall avatar kirill-konshin avatar c3riz88 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.