Dotenv mono
If this project has helped you out, please support us with a star 🌟
📘 Description
What is this?
This is a package that permit to load a dotenv even from a children applications or packages of a monorepo.
It contains also some additionals features like manipulations and save of the changes on the dotenv file.
The package dotenv-expand
is enabled by default.
Example
├── .env
├── packages
│ ├── my-package
│ │ ├── index.js
│ ├── my-package-2
│ │ ├── index.js
├── app
│ ├── nextjs
│ │ ├── next.config.js
│ ├── angular
│ │ ├── src
│ │ | ├── environment.ts
Priorities
This package find up, starting from the current process directory, the first file name that match the specific criterias.
Priority | File name |
---|
75 | .env.{development,production,test}.local |
50 | .env.local |
25 | .env.{development,production,test} |
0 | .env |
They can be customized on the constructor priorities
property, see the example below.
📖 Install
Install the library from npm or yarn just running one of the following command lines:
npm | yarn |
---|
npm install dotenv-mono --save | yarn add dotenv-mono |
💻 Usage
Load
const {dotenvLoad} = require("dotenv-mono");
const dotenv = dotenvLoad();
const {DotEnv} = require("dotenv-mono");
const dotenv = new DotEnv();
dotenv.load();
Load file with extension
dotenvLoad({extension: "server"});
Load specific file
dotenvLoad({path: "../../configs/.env"});
dotenvLoad({expand: false});
Change priorities
dotenvLoad({
priorities: {
".env.overwrite": 100,
},
});
Make changes
const dotenv = new DotEnv();
dotenv.loadFile();
dotenv.save({
"MY_ENV_1": "enjoy",
"MY_ENV_2": "'enjoy quotes'",
"MY_ENV_3": 999,
});
🤔 How to contribute
Have an idea? Found a bug? Please raise to ISSUES or PULL REQUEST.
Contributions are welcome and are greatly appreciated! Every little bit helps, and credit will always be given.