@confconf/dotenv
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

confconf .env file configuration provider

Features

Install

npm i --save @confconf/dotenv

Usage

import { confconf } from "@confconf/confconf";
import { dotenv } from "@confconf/dotenv";

// Define a schema
const configSchema = {
  // ...
};
type Config = {
  // ...
};

// Create the configuration loader
const configLoader = confconf<Config>({
  schema: configSchema,
  providers: [
    // Load all variables from .env file
    dotenv(),
    // or specify a path to the custom file with passing options:
    // dotenv({ path: ".env.my.vars" })
  ],
});

// Load configuration and validate it against the schema
const config = await configLoader.loadAndValidate();

API reference

dotenv(opts: DotenvProviderOpts)

Creates a new instance of the dotenv configuration provider

opts [DotenvProviderOpts]

interface DotenvProviderOpts {
  /**
   * Optional path to the environment variables file. Defaults to
   * path.resolve(process.cwd(), '.env')
   */
  path: string;
}

Package Sidebar

Install

npm i @confconf/dotenv

Weekly Downloads

9

Version

1.0.0

License

MIT

Unpacked Size

6.69 kB

Total Files

10

Last publish

Collaborators

  • tomiturtiainen