1.0.0 • Published 2 years ago

@boxpositron/vre v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Validate Runtime

Check if environmental variables exist and verify if their types

installation

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

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("validate-runtime-environment").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",
  }
);