Multiple `.env` file supported.

Overview

Features

Support multiple .env files and keep the inheritance

Priority:

  • local > not unassigned local
  • mode > not unassigned mode

e.g. .env.{{mode}}.local > .env.{{mode}} > .env.local > .env

# in .env file
HOST=127.0.0.1
PORT=3000
# in .env.local file
PORT=3001

# out
{"HOST": "127.0.0.1", "PORT": "3001"}

How to use

npm i dotenv-multi-x
# or
yarn add dotenv-multi-x
import dotenv from 'dotenv-multi-x'
dotenv.init()

console.log(process.env)

Methods

  • init
  • parse
  • getConfig

init

init will get mode from process.env or process.argv, read the .env* files, parse the content, handle the inheritance, and reture an object.

options : String[] your mode options list. Default: ['local', 'dev', 'production', 'test', 'release', 'staging']

demandOption : Boolean yargv demandOption, give user tips in command interface. Default: false

dotenv.init(['local', 'test', 'prod'])

parse

Parse the content and return an Object with the parsed keys and values.

dotenv.parse(Buffer.from('PROT=3001'))

getConfig

Accept a mode and read .env* files, and handle the inheritance. return finally result.

Example

# Windows Powershell
$env:mode="local"
node .\example\index.mjs
# Mac
mode=local node ./example/index.mjs

# or
node .\example\index.mjs --mode=local

Suggest

Add .env.local* in your .gitignore file.

Why not dotenv

When you run your code in multiple environments, you may need some different environments variable. But dotenv didn't support multiple .env files.

If you don't use docker or other CI/CD environment variable to instead of .env file, or don't use shell script to replace .env file, the multiple files is the easiest way to make it work.

For example, your server launched on port 3000, but you want to run on 3001 in local device, the .env file will be shared on repos which used git, so you need a .env.local file, this file has higher-priority then .env and it can doesn't share with git.

You can create mutiple .env* files, and use them in different environments as easier as possible.

You might also like...

Sheetzapper imports your account value accross Zapper.fi supported wallets and dapps into a Google Sheet

Sheetzapper imports your account value accross Zapper.fi supported wallets and dapps into a Google Sheet

Overview Sheetzapper imports your account value accross Zapper.fi supported wallets and dapps into a Google Sheet. This allows you to chart your net w

Nov 27, 2022

A container-friendly alternative to os.cpus().length. Both cgroups v1 and cgroups v2 are supported.

node-cpu-count A container-friendly alternative to os.cpus().length. Both cgroups v1 and cgroups v2 are supported. Installation $ npm install node-cpu

Jan 17, 2022

A website for detecting name of bank from card number, supported all Iranian banks

A website for detecting name of bank from card number, supported all Iranian banks

Detect Iranian Bank Web A website for detecting name of bank from card number, supported all Iranian banks. This package contains SVG logo and brand c

Oct 2, 2022

A decentralized protocol for indexing and querying data from DecentraMix's on chain contracts across all supported blockchains.

A decentralized protocol for indexing and querying data from DecentraMix's on chain contracts across all supported blockchains.

A decentralized protocol for indexing and querying data from DeMix contracts across all supported blockchains.

May 3, 2022

An Eleventy wrapper for type supported configurations

Shareable Eleventy configuration strap. The module can be dropped in to your .eleventy.js configuration file for Typed supported configuration options.

Jun 17, 2022

automatic poits grabber for twitch, works with all supported langauges on twitch

automatic poits grabber for twitch, works with all supported langauges on twitch

Twitch Points Grabber It’s an extension for edge, is aviable in the microsoft Edge Add-ons. This extension will collect any channel points. Settings I

Nov 28, 2022

The officially supported cloud storage plugin for Payload CMS.

Payload Cloud Storage Plugin This repository contains the officially supported Payload Cloud Storage plugin. It extends Payload to allow you to store

Dec 21, 2022

An obsidian plugin that allows code blocks executed interactively in sandbox like jupyter notebooks. Supported language rust、kotlin、python、Javascript、TypeScript etc.

An obsidian plugin that allows  code blocks executed interactively in sandbox like jupyter notebooks. Supported language rust、kotlin、python、Javascript、TypeScript etc.

Obsidian Code Emitter This plugin allows code blocks executed interactively like jupyter notebooks. Currently, support languages: Rust Kotlin JavaScri

Dec 28, 2022

A simple emotion picker that displays all the supported GitHub emojis :octocat:.

A simple emotion picker that displays all the supported GitHub emojis :octocat:.

github-emoji-picker A simple Emoji picker that displays all the emojis that GitHub supports. It is automatically generated from GitHub Emoji API and U

Dec 27, 2022
Owner
Tianyu Li
Code less, think more.
Tianyu Li
Export AWS SSM Parameter Store values in bulk to .env files

aws-parameter-bulk Utility to read parameters from AWS Systems Manager (SSM) Parameter Store in bulk and output them in environment-file or json forma

Adam Malik 18 Oct 18, 2022
Autocompletion, in-code secret peeking 🔎, syncing, and more, for your .env files in VSCode. 👑 From the same people who pioneered dotenv.

Dotenv Official (with Vault) for VSCode Official Dotenv. Syntax highlighting, autocompletion, in-code secret peeking, and .env file syncing with Doten

Dotenv 38 Dec 19, 2022
Infisical — Sync your .env securely in seconds.

Infisical Infisical is a simple, end-to-end encrypted secrets manager for your .env files. It enables teams to securely sync and manage .env files in

null 2.7k Jan 4, 2023
Loads environment variables from .env for nodejs projects.

dotenv Written in typescript, full testing. It can loads environment variables from a .env file into process.env or parse <key>=<value> string Install

Berlin 102 Sep 23, 2022
🔑 Loads environment variables from .env for nodejs projects with safe

env-safe env-safe is module that loads that loads environment variables from a .env file into process.env with type-safe. And can also validate the ty

Creatrip 9 Dec 28, 2022
A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ?? A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Ben Smith 21 Jun 20, 2022
Serve file server with single zip file as file system in Deno.

zipland Serve file server with one-single zip file in Deno. Support zip just zip32 with deflated or uncompressed serving plaintext deflate Examples Yo

Yongwook Choi 18 Nov 2, 2022
Feel free to create new file, don't hesitate to pull your code, the most important thing is that the file name here must match your nickname so that file does not conflict with other people.

Hacktoberfest Indonesia Apa Itu Hacktoberfest ? Hacktoberfest adalah acara tahunan yang bertujuan untuk mendorong berkontribusi kedalam ekosistem open

Juan Daniel 5 Dec 15, 2022
True P2P concept for your p2p powered website/app/client. MSC/MEP (Multiple Strategy Concept/Multiple Entry Points)

TRUE P2P CONCEPT - Lets redecentralize the web This repo is just conceptual. Active development of the endproduct (TRUE P2P) happens here https://gith

Bo 6 Mar 29, 2022
⚡🚀 Call multiple view functions, from multiple Smart Contracts, in a single RPC query!

ethers-multicall ⚡ ?? Call multiple view functions, from multiple Smart Contracts, in a single RPC query! Querying an RPC endpoint can be very costly

Morpho Labs 20 Dec 30, 2022