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
automates the process of keeping your
.env
in sync with .env.example
.
$ npm install -g sync-dotenv
Install as a dev dependency (recommended)
$ npm install -D sync-dotenv
By default, sync-dotenv
looks for a .env
in your working directory and
attempt to sync with .env.example
when no argument is provided. Failure
to find these files will cause the sync to fail.
$ sync-dotenv
For CLI options, use the --help
flag
$ sync-dotenv --help
Sync (with .env.example
) before every commit using husky
// package.json
{
"scripts": {
"env": "sync-dotenv"
},
"husky": {
"hooks": {
"pre-commit": "npm run env",
}
}
}
Or with file other than .env.example
{
"scripts": {
- "env": "sync-dotenv"
+ "env": "sync-dotenv --sample .env.development"
}
}
- 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 licensed under MIT