项目作者: mrsteele

项目描述 :
dotenv... but with defaults!
高级语言: JavaScript
项目地址: git://github.com/mrsteele/dotenv-defaults.git
创建时间: 2018-04-05T15:02:29Z
项目社区:https://github.com/mrsteele/dotenv-defaults

开源协议:MIT License

下载


dotenv-defaults

A dotenv system that supports defaults.

Status

npm
Main
dotenv-vault

Installation

Use the following to install this module:

  1. npm i dotenv-defaults --save

Usage

This module supports all the features from the original dotenv module, so usage should be simple enough:

  1. # .env.defaults, safe to commit
  2. HOST=website.com
  3. EMAIL=test@email.com
  1. # .env, DO NOT COMMIT
  2. HOST=mrsteele.dev

The result

  1. require('dotenv-defaults').config()
  2. // Or you can also load it directly like this
  3. require('dotenv-defaults/config')
  4. console.log(process.env.HOST)
  5. // Outputs: mrsteele.dev
  6. console.log(process.env.EMAIL)
  7. // Outputs: test@email.com
TypeScript

Since this module does not provide TypeScript Type Definitions if you try to import it like import dotenv from "dotenv-defaults" TypeScript will return an error.

Instead you should load it like this:

  1. import "dotenv-defaults/config"
CLI

You can also call this module directly when using the node executable.
So, for example if you are running a custom script with node and you want to load your environment variables you can do the following node -r dotenv-defaults/config your-script.js. (When using this method, please make sure that you have installed dotenv-defaults with npm or yarn in the same directory)

Differences

The only thing to note is that the original module supported an options argument in the config function.

This module supports that as well, but there is an added defaults property that can allow you to define where that file is located. An example is shown below:

  1. // all of these are the default values...
  2. require(`dotenv-defaults`).config({
  3. path: './.env',
  4. encoding: 'utf8',
  5. defaults: './.env.defaults' // This is new
  6. })

License

MIT