dotguard-cli
v1.0.1
Published
Production-ready environment variable validation and parsing for Node.js
Maintainers
Readme
dotguard
Production-ready environment variable validation and parsing for Node.js applications.
Strict, typed, and super configurable — so your apps never run with busted configs again.
🚀 Features
- 🔥 Runtime validation with full TypeScript support
- 🔢 Supports
string,number,boolean, andarraytypes - 🎯 Optional defaults & required variable enforcement
- 🎨 Beautiful CLI reporting with actionable feedback
- 🧩 Multi-file
.envsupport (.env.defaults,.env.local, etc.) - 🐳 Docker environment detection
- 📜 JSON schema generation for external tools
- 🔍 Detects unused environment variables to keep configs clean
📦 Installation
npm install dotguard
---
🛠️ Quickstart
1. Define your config schema
Create a dotguard.config.ts at your project root:
import { defineEnv } from 'dotguard'
export default defineEnv({
schema: {
PORT: {
type: 'number',
default: 3000,
description: 'Server port'
},
DATABASE_URL: {
type: 'string',
required: true,
description: 'Database connection string'
},
FEATURES: {
type: 'array',
separator: ',',
default: ['auth', 'api'],
description: 'Enabled features'
},
DEBUG: {
type: 'boolean',
default: false,
description: 'Enable debug mode'
}
},
dotenv: true,
files: ['.env.defaults', '.env', '.env.local'],
docker: true,
strict: true
})
2. Load and validate environment variables at runtime
import { createEnv } from 'dotguard'
const env = await createEnv<{
PORT: number
DATABASE_URL: string
FEATURES: string[]
DEBUG: boolean
}>()
console.log('Server running on port:', env.PORT)
3. Use the CLI for validation & tooling
# Validate your environment files
npx dotguard check
# Output parsed config as JSON
npx dotguard dump
# Generate JSON Schema file
npx dotguard gen-schema
---
🎯 Why dotguard?
Dotguard ensures your app configuration is bulletproof.
No more silent failures due to misconfigured env variables.
Get full typing, runtime validation, and awesome CLI feedback out of the box.
---
📄 License
MIT