• Stars
    star
    477
  • Rank 92,112 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Keep your .env in sync with .env.example

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 automates the process of keeping your .env in sync with .env.example.

Installation

$ npm install -g sync-dotenv

Install as a dev dependency (recommended)

$ npm install -D sync-dotenv

Usage

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

Alternatively, you can use the --env and --sample flag to specify the source and destination file.

$ sync-dotenv --env foo/.env --sample bar/.env.example

Also, in the situation where you want to keep multiple files in sync with one source env file you can make use of the --samples flag specifying a globbing pattern to match:

$ sync-dotenv --env foo/.env --samples "env-samples/*"

# note: glob pattern should be provided as a string as shown above

For CLI options, use the --help flag

$ sync-dotenv --help

To run sync-dotenv whenever the .env file changes, you can for example use nodemon:

$ nodemon --watch .env --exec 'sync-dotenv --env .env --sample .env.example'

Examples

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"
  }
}

Preserving variables in sample env

Sometimes you need to preserve certain variables in your example env file, you can optionally allow this by adding a sync-dotenv config in package.json like so

// package.json
"scripts": {
  ...
},
"sync-dotenv": {
  "preserve": ["CHANNEL"]
}

Avoid comments or empty lines in sample env

You might not want to copy empty lines or comments to your sample env, in this case you can still use sync-dotenv config in package.json with the following:

// package.json
"scripts": {
  ...
},
"sync-dotenv": {
  "emptyLines": true,
  "comments": false
}

Note that you can still combine those options with preserve.

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

πŸ’»
Kizito Akhilome
Kizito Akhilome

πŸ’» ⚠️ πŸ“–

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

License

This project is licensed under MIT

More Repositories

1

react-highlight-pop

React component for "medium-like" text highlight
JavaScript
52
star
2

sync-dotenv-slack

Keep .env in sync with teammates on Slack
TypeScript
51
star
3

lara-dotng

Twitter Bot for the awesome Public Transit Directions Assistant - Lara.ng
TypeScript
51
star
4

use-page-visibility

Dead-simple, React hook lib for detecting page visibility πŸ‘οΈ
JavaScript
48
star
5

twitter-mass-unfollow

A simple (configurable) way to mass unfollow your followings on Twitter
TypeScript
41
star
6

clipbot

Your personal clipboard manager
JavaScript
40
star
7

react-thanos

React hooks implementation of Google's "Thanos" easter egg
JavaScript
34
star
8

react-mitt

React event emitter / pubsub πŸ‘‰πŸ»πŸ‘ˆπŸ½
TypeScript
30
star
9

partnerengagements-push-notification

Automated push notifications of latest partner engagements for Andelans
JavaScript
27
star
10

1loc-vscode

VSCode extension for common JavaScript utilities in one line of code!
JavaScript
26
star
11

pingmydyno

Keep Heroku dynos awake forever β˜•οΈ
TypeScript
25
star
12

react-lock-screen

Simple lock-screen for idle React applications
JavaScript
11
star
13

whatsapp-web-status-downloader

One-click WhatsApp web status downloader 🐢
JavaScript
10
star
14

vue-regexr

A simple, beautiful tool for learning, testing and playing with regular expressions in real-time πŸŽ‰. Inspired by https://apptorium.com/expressions
Vue
9
star
15

parse-dotenv

Zero dependency .env to javascript object parser
TypeScript
8
star
16

pwakanda

πŸ”₯A progressive movie web app from Wakanda! πŸš€
JavaScript
6
star
17

amazon-cart-share

chrome extension that generates a shareable URL for your Amazon cart
JavaScript
6
star
18

node-postgres-api

A simple blog API built with Node.js + Express + PostgreSQL
JavaScript
3
star
19

next-github-finder

A GitHub user finder app built with NextJS & GraphQL
TypeScript
3
star
20

eatly-react

πŸ‘…A food delivery service app for a (fictional) restaurant built using ReactJS
JavaScript
2
star
21

ng-redundancy

This package, when required, aggressively makes your app redundant by terminating the node process with exit code 0
JavaScript
2
star
22

MovieTainment

Android app for discovering popular and recent movies in cinemas
Java
2
star
23

emaily

A full-stack React app πŸ‘Š
JavaScript
1
star
24

dotfiles-public

Shell
1
star
25

quran

Complete Quran in JSON format. Available in Arabic and English (Sahih international) translation
1
star
26

node-react-type-ahead

JavaScript
1
star
27

assets

1
star
28

use-kbd-list

Add full keyboard navigation support to your list component
TypeScript
1
star
29

currency-converter

An offline-first currency converter web app
JavaScript
1
star
30

nextjs-ts-starter

TypeScript
1
star
31

node-ts-starter

Node-TypeScript starter with ParcelJS
Shell
1
star
32

node-auth

JavaScript
1
star
33

awesome-test-coverage

Getting to 99.9% test coverage with mocks, stubs & spies using SinonJS
JavaScript
1
star
34

use-command-score

Tiny, fast fuzzy ⚑️earch for React applications
TypeScript
1
star