An open API service indexing awesome lists of open source software.

https://github.com/boxpositron/vre

Check if environmental variables exist and verify if their types
https://github.com/boxpositron/vre

dotenv nodejs package runtime typescript validation

Last synced: 3 days ago
JSON representation

Check if environmental variables exist and verify if their types

Awesome Lists containing this project

README

          

# Validate Runtime

Check if environmental variables exist and verify if their types

## installation

```shell
pnpm install @boxpositron/vre

or

npm install @boxpositron/vre

or

yarn add @boxpositron/vre
```

## Usage

Call the validate package the moment your application starts up and has loaded its environment. If there are missing environmental variables, the application will exit whilst displaying the missing parameters.

### Typescript

```ts
import validate, { RequiredEnvironmentTypes } from "validate-runtime-environment";

// Ensure you saturate your environment before calling validate
// You can use the dotenv package
// import dotenv from "dotenv";
// dotenv.config()

validate([
{
name: "MONGODB_URI",
type: RequiredEnvironmentTypes.String, // "string"
},
{
name: "PORT",
type: RequiredEnvironmentTypes.Number, // "number"
}
]);

```js
### Javascript

```ts
const validate = require("@boxpositron/vre").default;

// Ensure you saturate your environment before calling validate
// You can use the dotenv package
// import dotenv from "dotenv";
// dotenv.config()

validate([
{
name: "MONGODB_URI",
type: "string",
},
{
name: "PORT",
type: "number",
}
]);
```