https://github.com/leon0399/dotenv-modern
Modern loader for multiple .env files
https://github.com/leon0399/dotenv-modern
dotenv javascript
Last synced: 5 months ago
JSON representation
Modern loader for multiple .env files
- Host: GitHub
- URL: https://github.com/leon0399/dotenv-modern
- Owner: leon0399
- Created: 2022-09-23T23:12:08.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-18T22:49:35.000Z (over 1 year ago)
- Last Synced: 2025-05-28T00:36:01.656Z (about 1 year ago)
- Topics: dotenv, javascript
- Language: JavaScript
- Homepage:
- Size: 267 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
> **Deprecated**
> Use [`dotenvx`](https://github.com/dotenvx/dotenvx) or Node 20+ native [`--env-file`](https://nodejs.org/en/learn/command-line/how-to-read-environment-variables-from-nodejs#loading-env-files-programmatically-with-processloadenvfilepath) param
# dotenv-modern
`dotenv-modern` is more agile loader for multiple .env file for your projects, build on top of [dotenv](https://github.com/motdotla/dotenv) and [dotenv-expand](https://github.com/motdotla/dotenv-expand)
## Install
npm:
```bash
npm i dotenv-modern
```
Yarn:
```bash
yarn add dotenv-modern
```
pnpm:
```bash
pnpm i dotenv-modern
```
## Usage
`dotenv-modern` is a 100% substitute to [dotenv](https://github.com/motdotla/dotenv) and [dotenv-expand](https://github.com/motdotla/dotenv-expand) (cause it's build on top)
```diff
- require('dotenv').config()
+ require('dotenv-modern').config()
console.log(process.env) // remove this after you've confirmed it is working
```
or ES6
```diff
- import * as dotenv from 'dotenv'
+ import * as dotenv from 'dotenv-modern'
dotenv.config()
// All dependant imports, that rely on environment variable have to be placed AFTER loading dotenv config
import express from 'express'
```
### Dotenv files hierarchy
| Filename | Reccommended to .gitignore |
| :----------------------- | :------------------------- |
| `.env.${NODE_ENV}.local` | Yes |
| `.env.local ` | Yes |
| `.env.${NODE_ENV}` | No |
| `.env` | No |
Production build order: `.env.production.local`, `.env.local`, `.env.production`, `.env`
Development run: `.env.development.local`, `.env.local`, `.env.development`, `.env`
Running tests: `.env.development.local`, `.env.development`, `.env`