dotenv-expand
Expand environment variables using dotenv
Last updated 4 years ago by motdotla .
BSD-2-Clause · Repository · Bugs · Original npm
$ cnpm install dotenv-expand 
SYNC missed versions from official npm registry.

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

Current Tags

  • 10.0.0                                ...           latest (3 years ago)

5 Versions

  • 10.0.0                                ...           3 years ago
  • 8.0.3                                ...           3 years ago
  • 6.0.1                                ...           4 years ago
  • 5.1.0                                ...           6 years ago
  • 4.2.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (6)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org