
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@envchecker/env-validator
Advanced tools
A powerful environment variable validator for Node.js applications with schema validation, type checking, and security features
A powerful Node.js tool for validating environment variables against a predefined schema. Ensure your application's configuration is correct before startup.
✨ Type Validation: Validate numbers, strings, URLs, JSON objects, and arrays 🔒 Security: Mark sensitive variables to prevent logging 🎯 Pattern Matching: Use regex patterns to validate formats 📝 Custom Validation: Add your own validation functions 🔄 Conditional Validation: Require variables based on conditions 🎨 Pretty Output: Colorized CLI output for better readability
npm install @envchecker/env-validator
envchecker.config.js file in your project root:// Default envchecker.config.js
module.exports = {
REQUIRED_VARIABLES: {
PORT: {
type: 'number',
required: true,
min: 1024,
max: 65535
},
NODE_ENV: {
type: 'string',
required: true,
allowedValues: ['development', 'staging', 'production']
},
DATABASE_URL: {
type: 'url',
required: true,
pattern: '^postgres://'
},
API_KEY: {
type: 'string',
required: true,
sensitive: true,
minLength: 32
}
}
};
You can modify this file to match your project's requirements.
const { validateEnv } = require('@envchecker/env-validator');
const config = require('./envchecker.config.js');
try {
validateEnv(config);
console.log('Environment variables are valid!');
} catch (error) {
console.error('Validation failed:', error.errors);
process.exit(1);
}
npx @envchecker/env-validator
string: Text values
NAME: { type: 'string', minLength: 1, maxLength: 100 }
number: Numeric values
PORT: { type: 'number', min: 1024, max: 65535 }
boolean: True/false values
DEBUG: { type: 'boolean' }
url: URL strings
API_URL: { type: 'url', pattern: '^https://' }
json: JSON objects with schema validation
CONFIG: {
type: 'json',
schema: {
host: { type: 'string', required: true },
port: { type: 'number', required: true }
}
}
array: Array values
ALLOWED_IPS: { type: 'array' }
required: Make a variable mandatory
API_KEY: { type: 'string', required: true }
pattern: Validate against a regex pattern
EMAIL: { type: 'string', pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$' }
sensitive: Mark variables as sensitive to prevent logging
PASSWORD: { type: 'string', sensitive: true }
allowedValues: Restrict to specific values
LOG_LEVEL: { type: 'string', allowedValues: ['debug', 'info', 'warn', 'error'] }
validate: Custom validation function
VERSION: {
type: 'string',
validate: (value) => {
if (!/^\d+\.\d+\.\d+$/.test(value)) {
throw new Error('Must be a valid semantic version');
}
}
}
Require variables based on conditions:
module.exports = {
CONDITIONAL_VARIABLES: {
SSL_CERT: {
type: 'string',
required: (env) => env.NODE_ENV === 'production'
},
REDIS_URL: {
type: 'url',
required: (env) => env.CACHE_ENABLED === 'true'
}
}
};
# Basic validation
npx @envchecker/env-validator
# With verbose output
npx @envchecker/env-validator --verbose
# Using custom config file
npx @envchecker/env-validator --config ./config/env.config.js
Check out our examples directory for more detailed examples and use cases:
We welcome contributions! Please check out our contributing guidelines for details.
MIT
FAQs
A powerful environment variable validator for Node.js applications with schema validation, type checking, and security features
We found that @envchecker/env-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.