Skip to content
πŸš€ Create .env files based on CI environmental values
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
index.js
package-lock.json
package.json

README.md

πŸš€ Create-Env πŸš€

NPM Version License: MIT Build Status Coverage Status codecov npm

create-env is an utility to help you create .env files based on CI/CD environmental values.

Use case

You use Gitlab-CI/CD or another CI/CD to perform a build of a software artifact and you want to use the provided CI/CD secret variables as a .env file. This is where create-env comes to the rescue.

How it Works

You have defined your secret-variables inside of the CI/CD, and your variables uses a prefix like DEV_, TEST_, PROD_. create-env will take the current environment for your CI/CD pipeline, a prefix related to that environment, and the name of the file you want as output.

Then, it will generate that .env file, and remove the prefix of each secret-variable.

e.g:

  • Your secret-variables:
TEST_NODE_ENV=production
TEST_PORT=8080
  • Your .env file output:
NODE_ENV=production
PORT=8080

Installation

create-env needs to be installed as a global dependency:

NPM

npm i -g create-env

YARN

yarn global add create-env

Creating a .env file

To create a .env file you have to run create-env with the following parameters:

# Default
create-env --env-file .env --env-prefix TEST_

# NPX
npx create-env --env-file .env --env-prefix TEST_

create-env comes with a set of default prefixes (DEV_, TEST_, PROD_), if your secret-variables use those default prefixes, you can run create-env with the following parameters, the only thing your have to pass is the env which can be one of development, testing or production:

# Default
create-env --env testing --env-file .env --use-default-prefix

# NPX
npx create-env --env testing --env-file .env --use-default-prefix

TODO

  • Add --from-template option. (In order to support .env generation based on another .env file).
  • Add --no-prefix option. (In order to support generate a .env file with all the env variables).
  • Add --type option. (In order to support other formats like JSON envs).
  • Add --help option.

Issues

If you raise a bug, please, open an issue.

Contributing

PRs are welcome. Any kind of contribution is welcome.

License

create-env is licensed as MIT.

You can’t perform that action at this time.