env-preset
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

env-preset

The utility allows you to easily template your .env files by mapping it in .json.

Here's a simple example:

{
  "@extends": ".examples/prod/bar.json",

  "siteName": "Foo",
  "siteDomain": "example.com",
  "siteUrl": "https://{siteDomain}/help",

  "webmasterName": "webmaster",
  "webmasterEmail": "{webmasterName}@{siteDomain}",

  "debug": 0
}

vvv

# Autogenerated with env-preset
SITE_NAME=Foo
SITE_DOMAIN=example.com
SITE_URL=https://example.com/help
WEBMASTER_NAME=webmaster
WEBMASTER_EMAIL=webmaster@example.com
HELLO_FROM_BAR={"bar":"Hello World!"}
DEBUG=0

Installation

  1. The project requires Node v14 or higher. To install it, use npm:
npm install --save-dev env-preset
  1. After the installation create .epconfig.json and enter your preferences:
nano .epconfig.json

Available preferences:

{
  "input": ".examples/prod/foo.json",
  "envInput": ".env.example",
  "output": ".env",
  "depth": 3,
  "objDepth": 3,
  "logging": 0,
  "errorLogging": 1
}
  1. Compile your ENVs:
npx env-preset

You're all set!


Tips & Tricks

  1. You can set all preferences in .epconfig.json:
{
  "input": ".configs/prod.json",
  "output": ".env",
  "errorLogging": 0
}
  1. The "@extends" directive mixes your ENV with the target one:
{
  "@extends": ".examples/variables.json",
  "color": "{green}",
  "secondColor": "{blue}"
}
  1. You can use CLI to override the config:
env-preset --input .examples/prod.json --output .env

env-preset
by Kenny Romanov

Package Sidebar

Install

npm i env-preset

Weekly Downloads

20

Version

1.2.2

License

MIT

Unpacked Size

54.8 kB

Total Files

10

Last publish

Collaborators

  • kennyromanov