Skip to content

Getter and Setter 'process.env' variable from '.env' file

License

Notifications You must be signed in to change notification settings

iguntur/prop-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prop-env Build Status

Getter and Setter 'process.env' variable from '.env' file

Install

$ npm install --save prop-env

Usage

├── .env
├── index.js
└── package.json
// '.env' file
TWITTER_CONSUMER_KEY=gNiRPbQNG
TWITTER_CONSUMER_SECRET=95tpBUhR
const env = require('prop-env');

console.log(env('TWITTER_CONSUMER_KEY'));
//=> 'gNiRPbQNG'

console.log(env('TWITTER_CONSUMER_SECRET'));
//=> '95tpBUhR'

// set default value
console.log(env('TWITTER_TOKEN_KEY'));
//=> undefined

console.log(env('TWITTER_TOKEN_KEY', 'Umst0AZIiwex36'))
//=> 'Umst0AZIiwex36'

console.log(env('TWITTER_TOKEN_KEY'));
//=> 'Umst0AZIiwex36'

console.log(env('TWITTER_TOKEN_SECRET'));
//=> undefined

console.log(env('TWITTER_TOKEN_SECRET', 'LxU9qi9hAe'));
//=> 'LxU9qi9hAe'

// Can not override the value
console.log(env('TWITTER_TOKEN_SECRET', 'fooBar'));
//=> 'LxU9qi9hAe'

console.log(env('TWITTER_TOKEN_SECRET'));
//=> 'LxU9qi9hAe'

console.log(process.env);
/*
{
    // ...
    "TWITTER_CONSUMER_KEY": "gNiRPbQNG",
    "TWITTER_CONSUMER_SECRET": "95tpBUhR",
    "TWITTER_TOKEN_KEY": "Umst0AZIiwex36",
    "TWITTER_TOKEN_SECRET": "LxU9qi9hAe",
    // ...
}
*/

API

env(key, value, envFile)

Returns string value of process.env key

key

Type: string

process.env key

value

Set env value

envFile

Type: string
Default: process.cwd() + '/.env'

Set env path

License

MIT © Guntur Poetra

About

Getter and Setter 'process.env' variable from '.env' file

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published