Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iguntur/prop-env
Getter and Setter 'process.env' variable from '.env' file
https://github.com/iguntur/prop-env
env library node npm process utility
Last synced: about 9 hours ago
JSON representation
Getter and Setter 'process.env' variable from '.env' file
- Host: GitHub
- URL: https://github.com/iguntur/prop-env
- Owner: iguntur
- License: mit
- Created: 2017-02-13T16:35:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-02-13T16:52:31.000Z (over 7 years ago)
- Last Synced: 2024-10-30T01:44:36.529Z (9 days ago)
- Topics: env, library, node, npm, process, utility
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# prop-env [![Build Status](https://travis-ci.org/iguntur/prop-env.svg?branch=master)](https://travis-ci.org/iguntur/prop-env)
> 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
``````js
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'));
//=> undefinedconsole.log(env('TWITTER_TOKEN_KEY', 'Umst0AZIiwex36'))
//=> 'Umst0AZIiwex36'console.log(env('TWITTER_TOKEN_KEY'));
//=> 'Umst0AZIiwex36'console.log(env('TWITTER_TOKEN_SECRET'));
//=> undefinedconsole.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](http://iguntur.starmediateknik.com)