Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bin-huang/node-getenv
Get and parse environment variables more easily.
https://github.com/bin-huang/node-getenv
env environment-variables getenv nodejs
Last synced: 24 days ago
JSON representation
Get and parse environment variables more easily.
- Host: GitHub
- URL: https://github.com/bin-huang/node-getenv
- Owner: Bin-Huang
- License: mit
- Created: 2019-08-01T12:33:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T05:59:47.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T09:39:20.248Z (about 1 month ago)
- Topics: env, environment-variables, getenv, nodejs
- Language: TypeScript
- Homepage:
- Size: 207 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Get and parse environment variables more easily.
```
npm i node-getenv --save
``````javascript
const env = require('node-getenv')// PORT=8080 node index.js
const port = env.getNum('PORT') // 8080 (number)// CONSUMER_ON=on node index.js
env.getBool('CONSUMER_ON') // true// node index.js
env.getNum('CONCURRENCY', 4) // 4 (default value)// node index.js
env.requireNum('CONCURRENCY') // throw error
env.requireNumOrExit('CONCURRENCY') // log error, then process exit
```**getNum(key, defaults)**
Get environment variate in number type.
If the environment variate is undefined or not a valid number, return the default value.
**getStr(key, defaults)**
Get environment variate in string type.
If the environment variate is undefined, return the default value.
**getBool(key, defaults)**
Get environment variate in boolean type, supported values **without case sensitive**:
- Truly: `true`, `yes`, `on`, `open`, `t`, `y`, `1`.
- Falsely: `false`, `no`, `off`, `close`, `f`, `n`, `0`.
If the environment variate is undefined or unsupported, return the default value.
**bindEnv(defaultValues)**
Bind environment variates with default values, then returns them. It has no effect on real environmental variables (in `process.env`).
---------------------------------------
**License**: MIT