Customize env-doctor behavior with a configuration file.
Create env-doctor.config.js in your project root:
// env-doctor.config.js
module.exports = {
// Which env files to check
envFiles: ['.env', '.env.local'],
// Compare against this template
templateFile: '.env.example',
// Where to scan for usage
include: ['src/**/*.{ts,js,tsx,jsx}', 'app/**/*.{ts,js,tsx,jsx}'],
exclude: ['node_modules', 'dist', '**/*.test.*'],
// Framework (auto-detected by default)
framework: 'auto',
// Variable-specific rules
variables: {
DATABASE_URL: {
required: true,
secret: true,
pattern: /^postgres:\/\//
},
PORT: {
type: 'number',
default: 3000
},
NODE_ENV: {
enum: ['development', 'production', 'test']
}
},
// Ignore specific issues
ignore: [
'LEGACY_*', // Ignore by pattern
'unused:DEBUG', // Ignore specific rule
],
// Treat warnings as errors
strict: false,
};
env-doctor searches for config in this order:
env-doctor.config.jsenv-doctor.config.mjsenv-doctor.config.cjs.env-doctor.config.jsenv-doctor.config.json.env-doctorrcpackage.json "env-doctor" keyenvFilesArray of .env files to parse. Later files override earlier ones.
envFiles: ['.env', '.env.local', '.env.development.local']
templateFileTemplate file to compare against for sync checking.
templateFile: '.env.example'
includeGlob patterns for files to scan for process.env usage.
include: [
'src/**/*.{ts,js,tsx,jsx}',
'app/**/*.{ts,js,tsx,jsx}',
'pages/**/*.{ts,js,tsx,jsx}'
]
excludeGlob patterns to exclude from scanning.
exclude: [
'node_modules',
'dist',
'build',
'.next',
'**/*.test.*',
'**/*.spec.*'
]
frameworkFramework for applying specific rules. Options:
'auto' - Auto-detect (default)'nextjs' - Next.js'vite' - Vite'cra' - Create React App'node' - Plain Node.jsframework: 'nextjs'
variablesPer-variable rules for validation.
variables: {
DATABASE_URL: {
required: true, // Must be defined
secret: true, // Redact in output
pattern: /^postgres/ // Must match pattern
},
PORT: {
type: 'number', // Validate type
default: 3000 // Default if missing
},
LOG_LEVEL: {
enum: ['debug', 'info', 'warn', 'error']
},
API_URL: {
type: 'url', // Validate URL format
description: 'Backend API endpoint'
}
}
| Property | Type | Description |
|---|---|---|
required |
boolean |
Variable must be defined |
secret |
boolean |
Mark as sensitive |
type |
string |
Expected type: 'string', 'number', 'boolean', 'json', 'url', 'email' |
pattern |
RegExp |
Regex pattern to match |
default |
any |
Default value if not defined |
enum |
string[] |
Allowed values |
description |
string |
Documentation |
ignorePatterns for issues to ignore.
ignore: [
'LEGACY_*', // Ignore all LEGACY_ variables
'unused:DEBUG', // Ignore unused DEBUG variable
'missing:OPTIONAL_*', // Ignore missing OPTIONAL_ variables
]
Ignore patterns can be:
PATTERN - Ignore variable matching pattern for all rulesrule:PATTERN - Ignore specific rule for matching variablesstrictTreat warnings as errors (useful for CI).
strict: true
secretPatternsAdditional regex patterns for secret detection.
secretPatterns: [
/^MY_COMPANY_SECRET/,
/^INTERNAL_TOKEN/
]
Target specific environments with --env:
env-doctor --env production
This changes which .env files are checked:
| Environment | Files Checked |
|---|---|
development |
.env, .env.local, .env.development, .env.development.local |
production |
.env, .env.production, .env.production.local |
test |
.env, .env.test, .env.test.local |
You can also configure env-doctor in package.json:
{
"env-doctor": {
"envFiles": [".env", ".env.local"],
"templateFile": ".env.example",
"framework": "nextjs",
"strict": true
}
}
For TypeScript config files, use .mjs extension:
// env-doctor.config.mjs
/** @type {import('env-doctor').EnvDoctorConfig} */
export default {
envFiles: ['.env'],
framework: 'nextjs',
};