https://github.com/kth/reqvars
https://github.com/kth/reqvars
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kth/reqvars
- Owner: KTH
- License: mit
- Created: 2019-08-27T11:53:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T09:58:50.000Z (about 2 years ago)
- Last Synced: 2025-01-02T07:16:09.621Z (over 1 year ago)
- Language: JavaScript
- Size: 1.18 MB
- Stars: 0
- Watchers: 13
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/KTH/reqvars)
# reqvars
Check that [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env) contains all the **req**uired **var**iable**s**!
## Install
```sh
npm i @kth/reqvars
```
## Usage
1. Write a `.env.in` saying which environmental variables are required in your program. This will be your **specification file**.
For example:
```ini
DB_HOST=localhost
DB_USER=root
DB_PASS=
```
If you commit the file (which is recommended) remember to leave the secrets (passwords, etc.) blank
2. As early as possible in your application, require `reqvars` and call `check`:
```js
require('@kth/reqvars').check()
```
It will compare the `process.env` object against your **specification file** and throw an error if something is missing. By default it will look at the `.env` file in the root of your project.
3. If you want to use another file as specification file, pass the path as argument:
```js
require('@kth/reqvars').check('./requirements.conf')
```
## Tips
### Usage with `dotenv`
If you use [`dotenv`](https://github.com/motdotla/dotenv), use it *before* `reqvars`:
```js
require('dotenv').config()
require('@kth/reqvars').check()
```
### Format for `.env.in`
The `.env.in` should be human readable. Document all fields as best as possible. For example:
```ini
# Credentials for the internal database. It should be a MySQL database.
DB_HOST=localhost
DB_USER=root
DB_PASS=
```