A robust, secure environment variable management library for Node.js with validation, encryption, and AWS Secrets Manager integration.
- ✅ Environment variable validation with Joi schemas
- ✅ AWS Secrets Manager integration (using AWS SDK v3)
- ✅ Encryption/Decryption of sensitive values using AES-256-GCM
- ✅ TypeScript support with full type definitions
- ✅ Multiple environment support (development, production, test)
- ✅ Type checking and default values
- ✅ Graceful error handling with detailed error messages
npm install advanced-env-manager- Node.js 18 or higher
- For AWS Secrets Manager: AWS credentials configured
import EnvManager from 'advanced-env-manager';
import Joi from '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();const { EnvManager } = require('advanced-env-manager');
const Joi = require('joi');
// ... same as aboveMain class for managing environment variables.
interface EnvManagerOptions {
encryptionKey?: string; // Encryption key (or set ENV_ENCRYPTION_KEY)
envPath?: string; // Path to .env file (default: '.env')
schema?: Schema; // Joi schema for validation
useCloud?: boolean; // Enable AWS Secrets Manager (default: false)
}initialize(): Promise<EnvConfig>- Loads and validates environment variablesencrypt(value: string): string- Encrypts a sensitive valuedecrypt(encryptedValue: string): string- Decrypts an encrypted value
See the examples directory for more usage examples:
NODE_ENV: Application environment (development/production/test)PORT: Application portDATABASE_URL: Database connection stringENV_ENCRYPTION_KEY: Key for encrypting sensitive values (32+ characters recommended)
AWS_REGION: AWS region for Secrets Manager (default: us-east-1)AWS_SECRET_NAME: Name of the secret in AWS Secrets Manager (default: 'default')
- Clone the repository
- Install dependencies:
npm install - Run tests:
npm test - Run tests with coverage:
npm run test:coverage - Run linter:
npm run lint - Format code:
npm run format
npm run build- Encryption Key: Use a strong, random encryption key (32+ characters). Store it securely and never commit it to version control.
- AWS Credentials: Configure AWS credentials using AWS CLI, IAM roles, or environment variables. Never hardcode credentials.
- Environment Files: Add
.envfiles to.gitignoreto prevent committing sensitive data.
Contributions are welcome! Please feel free to submit a Pull Request.
- Rikwu Godwin Onyung
- Ghedinaeval Charles Don-Ibor
- Michael Fredrick Ikaka
- Godfrey Lebo
ISC