Skip to content
/ dotenv Public
forked from motdotla/dotenv

Loads environment variables from .env for nodejs projects.

Notifications You must be signed in to change notification settings

bryanph/dotenv

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotenv

Dotenv loads environment variables from .env into ENV (process.env).

BuildStatus NPM version

"Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.

But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a .env file into ENV when the environment is bootstrapped."

Brandon Keepers' Dotenv in Ruby

Installation

As early as possible in your application require dotenv and load the .env variables.

var dotenv = require('dotenv');
dotenv.load();

IMPORTANT: In pre 0.2.3, you instantiated dotenv like the following with the bagels.

var dotenv = require('dotenv')();
dotenv.load();

Usage

Add your application configuration to your .env file in the root of your project:

S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE
SENDGRID_USERNAME=YOURSENDGRIDUSERNAME
SENDGRID_PASSWORD=YOURSENDGRIDPASSWORDGOESHERE

Whenever your application loads, these variables will be available in process.env:

var sendgrid_username = process.env.SENDGRID_USERNAME;

Should I commit my .env file?

Try not to commit your .env file to version control. It is best to keep it local to your machine and local on any machine you deploy to. Keep production credential .envs on your production machines, and keep development .envs on your local machine.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Running tests

npm install
npm test

About

Loads environment variables from .env for nodejs projects.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%