Skip to content

benisi/sync-dotenv

 
 

Repository files navigation

sync ⚙️ dotenv

Keep your .env in sync with .env.example

Travis (.org) Coveralls github

Motivation

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 🔥

Description

sync-dotenv is a tiny module that helps automate the process of keeping your .env file in sync with .env.example.

Installation

$ npm install sync-dotenv --save

or using yarn

$ yarn add sync-dotenv

Usage

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
}

API

syncEnv(filename)

filename

A string representing the (existing or new) example env file to sync with (relative to project root).

Type: String

Default: .env.example

Related

  • parse-dotenv - zero dependency .env to javascript object parser

Contributors

Thanks goes to these wonderful people (emoji key):

Luqman Olushi O.
Luqman Olushi O.

💻 📖 🚧 📦 ⚠️
Bolaji Olajide
Bolaji Olajide

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project is license under MIT

About

Keep your .env in sync with .env.example

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%