Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loadenv

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loadenv

Loads environment variables from project's `./configs/` directory based on NODE_ENV.

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27
decreased by-35.71%
Maintainers
2
Weekly downloads
 
Created
Source

loadenv

Build Status Dependency Status devDependency Status

NPM

Utility for loading environment variables from a project's configs/ directory.

How it works

The module first finds your application's root directory and then attempts to load environment variables found in the configs/.env file. Then, if a specific NODE_ENV exists in the environment at run time it additionally loads variables from the configs/.env.${NODE_ENV} file. Note: This module will not work if installed globally [npm install loadenv -g].

An Example

Suppose you have your project setup with the following configs:

configs/.env
  A=1
  B=2
configs/.env.test
  B=3
  C=4

If you launched your application without a NODE_ENV variable set, and called into the module like so:

require('loadenv')();

then the resulting process.env would now contain the following:

process.env.A === 1
process.env.B === 2

If instead, you launched your application with NODE_ENV=test then the process.env would include the following:

process.env.A === 1
process.env.B === 3
process.env.C === 4

Logging the Resulting Environment

The module uses debug to log the resulting environment after it has been loaded from the configs/ files. By default it uses debug('loadenv') but you can override this by calling into the module with a custom name, like so:

// Pass an options object:
require('loadenv')({
  debugName: 'myapp:env'
});

// Or just use a string if you only need the debug name
require('loadenv')('myapp:env') ;

If you were to do so then the module would use debug('myapp:env') to log the resulting output.

Only Loads Environment Once

No matter how many times you include the module, the environment is only loaded once. So feel free to sprinkle loads wherever they might be needed to make your code as modular as possible.

Developing

If you want to contribute, make sure that all tests pass with 100% coverage before submitting a pull request. Here's how to run the tests:

npm test

LICENSE

MIT

FAQs

Package last updated on 15 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc