node-dotenv
v1.1.1
Published
nodejs environment variables configurator
Downloads
17
Readme
NodeJS Dot Environments
This library exports all pairs (key=value) from .env
-file to process.env
-object.
This makes it very easy to configure your application using the environment variables.
Install
$ npm i node-dotenv
Usage
"use strict";
const dotEnv = require('node-dotenv')(); //It's enough
// or with an explicit file path
dotEnv = require('node-dotenv')('../file/path/to/.env'); //It's enough
//if you want get all vars from .env
dotEnv.then(envVars => console.log(envVars));
File path to .env
.env
-file search stage (places):
- parameter passed in the call module;
- value from environment variable
NODE_DOT_ENV_PATH
; - in root directory of your project;
- as a result of call
dirname(require.main.filename)
.
Example .env
-file structure:
varName1=varVal1
varName2=varVal2
varName3=varVal3
...
varNameN=varValN
...
Comments in .env
You can commented some strings of .env
-file like follow:
varName1=varVal1
#varName2=varVal2
varName3=varVal3
String started with #
will not be parse.
License
Licensed under the MIT License