inforce-env
v0.1.2
Published
**A TypeScript package to check if environment variables are set.**
Downloads
4
Readme
Inforce Env
A TypeScript package to check if environment variables are set.
Description
Env Exist is a TypeScript package that helps you to check if environment variables are set. It takes a list of environment variable names as input and returns a boolean value indicating whether all of the variables are set.
Installation
npm install inforce-env
Usage
import { checkIfEnvsAreSet } from 'inforce-env';
// Check if the environment variables `API_KEY` and `DATABASE_URL` are set
checkIfEnvsAreSet(['API_KEY', 'DATABASE_URL']);
// Check if the environment variables `API_KEY` and `DATABASE_URL` are set, and exit the process if any of them are not set
checkIfEnvsAreSet(['API_KEY', 'DATABASE_URL'], true);
Options
The checkIfEnvsAreSet()
function takes two optional parameters:
envs
: An array of environment variable names to check.exit
: A boolean value indicating whether to exit the process if any of the environment variables are not set. The default value isfalse
.
Examples
// Check if the environment variable `API_KEY` is set
checkIfEnvsAreSet(['API_KEY']);
// Check if the environment variables `API_KEY` and `DATABASE_URL` are set, and exit the process if any of them are not set
checkIfEnvsAreSet(['API_KEY', 'DATABASE_URL'], true);
Benefits
- Helps you to ensure that your application has all of the environment variables it needs to run.
- Can be used to prevent your application from crashing if an environment variable is not set.
- Easy to use and integrate into your application.