Projects often rely on environmental variables stored in a .env
file to run... and because these
variables sometimes contain sensitive data, we never add them to source control.
Instead, these variables are added e.g. to a .env.example
file so it's easy to
get the project running for other developers. However, it's very easy to forget to update this file
when a variable is added/updated in .env
(during development). This can make
it difficult for devs to get the project running (locally) because they rely on
.env.example
file to setup their environment (with their own configs).
Enter sync-dotenv
🔥
sync-dotenv
is a tiny module that helps automate the process of keeping your .env
file in sync with .env.example
.
$ npm install sync-dotenv --save
or using yarn
$ yarn add sync-dotenv
By default, sync-dotenv
looks for a .env
file in your project root. Failure
to find this file will cause it to throw an error.
const syncEnv = require("sync-dotenv");
syncEnv(); // use exisiting .env.example or create one
const syncEnv = require("sync-dotenv");
syncEnv(".env.development");
Handling error when there's no .env
const syncEnv = require("sync-dotenv");
try {
syncEnv();
} catch (error) {
console.log(error.message); // .env not found
}
A string representing the (existing or new) example env file to sync with (relative to project root).
Type: String
Default: .env.example
- parse-dotenv - zero dependency .env to javascript object parser
Thanks goes to these wonderful people (emoji key):
Luqman Olushi O. 💻 📖 🚧 📦 | Bolaji Olajide 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
This project is license under MIT