Socket
Socket
Sign inDemoInstall

12factor-dotenv

Package Overview
Dependencies
3
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    12factor-dotenv

Include dotenv files in relative path tree, and parse with 12factor config


Version published
Maintainers
1
Install size
874 kB
Created

Changelog

Source

0.1.6 (2016-12-13)

Features
  • env: added env to options object param to allow customization of env() loading (2a9dcd00)

Readme

Source

12factor-dotenv

npm version Build Status

NPM downloads

Automagically Load Dotenv Files (.env)

This module looks for .env files loads them with node-env-file and returns a 12factor-config

Features

  • relative to parent module
    • note: Parent module is one that requires 12factor-dotenv
  • loads .env files in an ascending relative path:
    • ./
    • ../
    • ../../

Install

npm install 12factor-dotenv --save

Config schema

This module uses 12factor-config to manage a config schema, for configuration support, Read More Here

Usage

in a single config file (obey 12factor and unify your config location), do something like:

// in ./app/lib/config.js

var config = require('12factor-dotenv');
var schema = {
	DEBUG: {
		env: 'DEBUG', // the environment export var to read
		type: 'boolean', // config var type (string, integer, boolean - maybe more see 12factor-config)
		default: false
	},
	PORT: {
		env: 'PORT',
		type: 'integer',
		default: 4000
	},
	MY_CUSTOM_VAR: {
		env: 'MY_LOCAL_ENVIRONMENT_EXPORT_VAR',
		type: 'string'
	},
	NODE_ENV: {
		env: 'NODE_ENV',
		type: 'string',
		default: 'development'
	}
};

var cfg = config(schema, { debug: true, env: { overwrite: true } });

## See https://www.npmjs.com/package/node-env-file#api for more details on `env` options

console.log('info: -- PORT is', cfg.PORT);
console.log('info: -- NODE_ENV is', cfg.NODE_ENV);

console.log('debug: -- ENV Debug is', process.env.DEBUG);
console.log('debug: -- ENV Port is', process.env.PORT);

console.log('info: < Configured.');

module.exports = exports = cfg;

now var cfg = require('./path/to/app/lib/config.js'); wherever you want your unified config - and keep .env(s) updated per environment.

Note!

This package also loads native process.env variables, when parsing .env files

Keywords

FAQs

Last updated on 16 Dec 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc