Giter Club home page Giter Club logo

dotenv-updater's Introduction

npm (scoped) npm

Dotenv Updater

Dotenv Updater is a module that keeps your local, gitignored, .env files up to date with the latest variables defined in a dist/example file, like .env.example.

It compares your .env file with the .env.example (or other file specified in config), and if there any variables missing from your .env file it will interactively prompt you for their values on the command line, and update your .env file for you.

Install

# with npm
npm install --save-dev @caxy/dotenv-updater

# or with Yarn
yarn add --dev @caxy/dotenv-updater

Usage

The primary use-case is to run this script alongside your other npm/Yarn scripts defined in your package.json.

For example, you can add calls to dotenv-updater at the beginning of your commonly run scripts, so that you can ensure you'll always have an up-to-date env file.

# in your package.json

"scripts": {
  "start": "dotenv-updater && node dist/index.js",
  "build": "dotenv-updater && ..."
},
...

You can also run it manually from the command line at the root of the project (or anywhere if installed globally):

dotenv-updater

Configuration

You can add configuration in your package.json file to modify some of the default settings, which you will definitely want to do if your dist file is not named .env.example.

Below shows the configuration options available and their default values.

# in your package.json

{
  # ...

  "dotenvUpdater": {
    "envFile": ".env",
    "distFile": ".env.example",
    "checkExtraVars": true
  }
}

Options

Option name Description Default value
envFile The name of the local env file. This is the file that will be updated with new variables found in the distFile. This file is often ignored and excluded from source control since it may contain sensitive information. ".env"
distFile The name of the "dist" env file, which serves as the empty template for the environment variables that are available to be defined. This file is often tracked in the repository and has default/placeholder values. ".env.example"
checkExtraVars Boolean flag to enable/disable the "check extra vars" feature. When set to true, the script will check to see if there are any variables defined in the envFile that are not defined in the distFile. If any are found, a message will be printed to the console indicating that there are extra variables not found in the dist file and will include which variables.

The idea here is that if there are any extra variables in the envFile, they might be outdated / no longer used and can be removed, or it might be an indication that the distFile is missing some variables that are used and they should be updated with those.

This will not remove any variables from the envFile, it will only log a message to the console.
true

dotenv-updater's People

Contributors

dependabot[bot] avatar jschroed91 avatar nickdubois avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.