This package enhances environment variable management by adding validation, type checking, and cloud integration, making projects more secure.
- Environment variable validation with Joi schemas
- AWS Secrets Manager integration
- Environment variable encryption
- Multiple environment support
- Type checking and default values
npm install advanced-env-manager
const EnvManager = require('advanced-env-manager');
const Joi = require('joi');
// Define your schema
const schema = Joi.object({
NODE_ENV: Joi.string().valid('development', 'production', 'test').required(),
PORT: Joi.number().default(3000),
DATABASE_URL: Joi.string().uri().required(),
});
// Initialize the manager
const envManager = new EnvManager({
encryptionKey: 'your-encryption-key',
envPath: '.env',
schema: schema,
useCloud: true // Set to true to use AWS Secrets Manager
});
// Use the manager
async function start() {
try {
const config = await envManager.initialize();
console.log('Environment configured:', config);
// Encrypt sensitive data
const encrypted = envManager.encrypt('sensitive-value');
console.log('Encrypted:', encrypted);
// Decrypt when needed
const decrypted = envManager.decrypt(encrypted);
console.log('Decrypted:', decrypted);
} catch (error) {
console.error('Configuration error:', error);
}
}
start();
- Clone the repository
- Copy
.env.example
to.env
and fill in your values - Install dependencies:
npm install
- Run tests:
npm test
-
NODE_ENV
: Application environment (development/production/test) -
PORT
: Application port -
DATABASE_URL
: Database connection string -
ENV_ENCRYPTION_KEY
: Key for encrypting sensitive values -
AWS_REGION
: AWS region for Secrets Manager -
AWS_SECRET_NAME
: Name of the secret in AWS Secrets Manager
- Rikwu Godwin Onyung
- Ghedinaeval Charles Don-Ibor
- Michael Fredrick Ikaka
ISC