function ConfigPlugin
Since 0.1.0
ConfigPlugin(options?: ConfigPluginOptions): IPlugin

Creates the ConfigPlugin.

The plugin depends on the runtime plugin (CAPABILITIES.RUNTIME) and registers its IConfig under CAPABILITIES.CONFIG at PLUGIN_PRIORITY.HIGH (100) so configuration is available before most other plugins register.

Registration may be async because env files are loaded asynchronously through runtime.fs.

Examples

Example 1

import { ConfigPlugin } from '@setu-ts/config-plugin';
import { z } from 'npm:zod';

const AppConfigSchema = z.object({
  PORT: z.coerce.number().default(3000),
  DATABASE_URL: z.string().url(),
});

app.register(ConfigPlugin({
  envFilePath: ['.env.local', '.env'],
  validationSchema: AppConfigSchema,
  expandVariables: true,
}));

Parameters

optional
options: ConfigPluginOptions

Plugin configuration

Return Type

IPlugin

The plugin instance

Usage

import { ConfigPlugin } from "config-plugin/src/index.ts";