secure-env-shield
v1.0.0
Published
A type-safe environment variable parser and validator.
Maintainers
Readme
env-shield
A robust, type-safe environment variable parser and validator for Node.js, Bun, and Frontend projects.
Ensure your application never starts with missing or malformed configuration.
Installation
npm install env-shieldUsage
Define your schema, and env-shield will automatically validate and infer TypeScript types!
import { parseEnv } from 'env-shield';
// By default it reads from process.env if available
const config = parseEnv({
PORT: { type: 'number', default: 3000 },
DATABASE_URL: { type: 'url' },
NODE_ENV: { type: 'string', choices: ['development', 'production', 'test'], default: 'development' },
ENABLE_FEATURE_X: { type: 'boolean', required: false }
});
// `config` is fully typed!
// config.PORT is `number`
// config.DATABASE_URL is `string`If validation fails, it throws an EnvValidationError detailing exactly which variables are missing or incorrectly formatted, preventing cryptic runtime errors later in your application lifecycle.
