2.2.1 • Published 2 years ago

@confconf/confconf-typebox v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

confconf-typebox

Integrates @confconf/confconf with @sinclair/typebox.

Install

npm i --save @confconf/confconf-typebox @sinclair/typebox

Usage

import { confconf, envConfig } from "@confconf/confconf-typebox";
import { Static, Type } from "@sinclair/typebox";

// Define a schema
const configSchema = Type.Object({
  port: Type.Number(),
  db: Type.Object({
    host: Type.String(),
    name: Type.String(),
  }),
});

type Config = Static<typeof configSchema>;

// Create the configuration loader and load configuration and validate
// it against the schema
const config = await confconf({
  schema: configSchema,
  providers: [
    // Load from env variables
    envConfig({
      // Map the specifc env variables into a specific structure
      structure: {
        port: "PORT",
        db: {
          host: "DB_HOST",
          name: "DB_NAME",
        },
      },
    }),
  ],
}).loadAndValidate();