Skip to main content

dotenv

@inversifyjs/config-dotenv provides an envFile source that parses .env files without mutating process.env.

Install

npm install @inversifyjs/config-dotenv

envFile

interface EnvFileOptions {
path?: string | string[];
}
  • Defaults to .env when path is omitted.
  • Missing files are ignored.
  • When multiple paths are provided, later files override earlier ones.
import { type ConfigSource } from '@inversifyjs/config';
import { envFile } from '@inversifyjs/config-dotenv';

export const source: ConfigSource = envFile({
path: ['.env', `.env.${process.env['NODE_ENV'] ?? 'development'}`],
});