prop-env

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i prop-env

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • guntur