Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mglagola/validate-env
Validate your env variables, avoiding future headaches or points of failure!
https://github.com/mglagola/validate-env
javascript node npm validation validator yarn
Last synced: 21 days ago
JSON representation
Validate your env variables, avoiding future headaches or points of failure!
- Host: GitHub
- URL: https://github.com/mglagola/validate-env
- Owner: mglagola
- Created: 2017-06-23T13:26:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-23T13:35:47.000Z (over 7 years ago)
- Last Synced: 2024-10-05T16:41:41.649Z (about 1 month ago)
- Topics: javascript, node, npm, validation, validator, yarn
- Language: JavaScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Validate your env variables
Avoid the scenerio where your app doesn't work properly because you're missing an environment variable.
## Installation
```bash
$ npm install validate-env --save
# ... or
$ yarn add validate-env```
## Usage Examples:
**1.** First option is to use `validateEnvVariables` default functionality, which throws an `Error` on failure.
```js
const { validateEnvVariables } = require('validate-env');try {
validateEnvVariables(['GOOGLE_API_KEY', 'AWS_SECRET_KEY']);
} catch (error) {
console.error(error);
process.exit(1);
}```
**2.** Or you can disable `throwsOnFailure` functionality, meaning `validateEnvVariables` will now return `false` when env variables are invalid.
```js
const { validateEnvVariables } = require('validate-env');if (!validateEnvVariables(['GOOGLE_API_KEY', 'AWS_SECRET_KEY'], { throwsOnFailure: false })) {
console.log('One or more env vars are missing!');
process.exit(1);
}
```