# 12factor-dotenv

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

Latest version **0.1.6** (published 2016-12-16) · 0 weekly downloads

## Install

```sh
npm install 12factor-dotenv
pnpm add 12factor-dotenv
yarn add 12factor-dotenv
bun add 12factor-dotenv
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2016-12-16 |
| First published | 2015-04-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | electblake |
| Maintainers | electblake |
| Keywords | config, env, environment, 12factor, process, file, files, .env, process.env, parse, load, export, exports |

## Links

- npm: https://www.npmjs.com/package/12factor-dotenv
- Repository: https://github.com/electblake/node-12factor-dotenv
- Issues: https://github.com/electblake/node-12factor-dotenv/issues
- npm.io page: https://npm.io/package/12factor-dotenv

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^3.6.0
- [node-env-file](https://npm.io/package/node-env-file.md) ^0.1.7
- [12factor-config](https://npm.io/package/12factor-config.md) ^1.0.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 0.1.6 (latest) — 2016-12-16
- 0.1.5 — 2015-06-26
- 0.1.4 — 2015-06-26
- 0.1.3 — 2015-04-14
- 0.1.2 — 2015-04-14
- 0.1.1 — 2015-04-14
- 0.0.5 — 2015-04-14
- 0.0.4 — 2015-04-11
- 0.0.3 — 2015-04-11

## README

# 12factor-dotenv

[![npm version](https://badge.fury.io/js/12factor-dotenv.svg)](https://npmjs.org/package/12factor-dotenv "View this project on NPM")
[![Build Status](https://img.shields.io/travis/electblake/node-12factor-dotenv.svg?branch=master)](http://travis-ci.org/electblake/node-12factor-dotenv "Check this project's build status on TravisCI")

[![NPM downloads](https://img.shields.io/npm/dm/12factor-dotenv.svg)](https://npmjs.org/package/12factor-dotenv "View this project on NPM")


## Automagically Load Dotenv Files (`.env`)

This module looks for `.env` files loads them with [node-env-file](https://www.npmjs.com/package/node-env-file) and returns a [12factor-config](https://www.npmjs.com/package/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](https://www.npmjs.com/package/12factor-config)

# 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

---
_Source: https://npm.io/package/12factor-dotenv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
