Giter Site home page Giter Site logo

adibenmati / dotenv-expand Goto Github PK

View Code? Open in Web Editor NEW

This project forked from motdotla/dotenv-expand

0.0 0.0 0.0 301 KB

Variable expansion for dotenv. Expand variables already on your machine for use in your .env file.

License: BSD 2-Clause "Simplified" License

JavaScript 86.53% Shell 12.48% TypeScript 0.99%

dotenv-expand's Introduction

Announcement ๐Ÿ“ฃ
From the makers that brought you Dotenv, introducing Dotenv Sync.
Sync your .env files between machines, environments, and team members.
Join the early access list.๐Ÿ’›

dotenv-expand

dotenv-expand

Dotenv-expand adds variable expansion on top of dotenv. If you find yourself needing to expand environment variables already existing on your machine, then dotenv-expand is your tool.

BuildStatus NPM version js-standard-style

Install

# Install locally (recommended)
npm install dotenv --save
npm install dotenv-expand --save

Or installing with yarn? yarn add dotenv-expand

Usage

Usage is a cinch!

1. Create a .env file with variable expansions in the root directory of your project

# .env file
#
# Add environment-specific variables on new lines in the form of NAME=VALUE
#
PASSWORD=s1mpl3
DB_HOST=localhost
DB_USER=root
DB_PASS=$PASSWORD

2. As early as possible in your application, import dotenv and expand with dotenv-expand

var dotenv = require('dotenv')
var dotenvExpand = require('dotenv-expand')

var myEnv = dotenv.config()
dotenvExpand.expand(myEnv)

console.log(process.env)

3. That's it! ๐Ÿ‘

process.env now has the expanded keys and values you defined in your .env file.

Examples

See test/.env for simple and complex examples of variable expansion in your .env file.

Documentation

DotenvExpand exposes one function:

  • expand

Expand

expand will expand your environment variables.

const dotenv = {
  parsed: {
    BASIC: 'basic',
    BASIC_EXPAND: '${BASIC}',
    BASIC_EXPAND_SIMPLE: '$BASIC'
  }
}

const obj = dotenvExpand.expand(dotenv)

console.log(obj)

Options

ignoreProcessEnv

Default: false

Turn off writing to process.env.

const dotenv = {
  ignoreProcessEnv: true,
  parsed: {
    SHOULD_NOT_EXIST: 'testing'
  }
}
const obj = dotenvExpand.expand(dotenv).parsed

console.log(obj.SHOULD_NOT_EXIST) // testing
console.log(process.env.SHOULD_NOT_EXIST) // undefined

FAQ

What rules does the expansion engine follow?

The expansion engine roughly has the following rules:

  • $KEY will expand any env with the name KEY
  • ${KEY} will expand any env with the name KEY
  • \$KEY will escape the $KEY rather than expand
  • ${KEY:-default} will first attempt to expand any env with the name KEY. If not one, then it will return default

You can see a full list of examples here.

Contributing Guide

See CONTRIBUTING.md

CHANGELOG

See CHANGELOG.md

Who's using dotenv-expand?

These npm modules depend on it.

dotenv-expand's People

Contributors

chatcher avatar dependabot[bot] avatar ericrallen avatar felixmosh avatar guyathomas avatar iansu avatar javiacei avatar legendar avatar mfaheemakhtar avatar michaeldeboey avatar mikailbag avatar motdotla avatar mrsteele avatar vantreeseba avatar wormss 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.