1.0.3 • Published 5 months ago
advanced-env-manager v1.0.3
Advanced Environment Manager
This package enhances environment variable management by adding validation, type checking, and cloud integration, making projects more secure.
Features
- Environment variable validation with Joi schemas
- AWS Secrets Manager integration
- Environment variable encryption
- Multiple environment support
- Type checking and default values
Installation
npm install advanced-env-manager
Usage
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();
Testing Locally
- Clone the repository
- Copy
.env.example
to.env
and fill in your values - Install dependencies:
npm install
- Run tests:
npm test
Environment Variables
NODE_ENV
: Application environment (development/production/test)PORT
: Application portDATABASE_URL
: Database connection stringENV_ENCRYPTION_KEY
: Key for encrypting sensitive valuesAWS_REGION
: AWS region for Secrets ManagerAWS_SECRET_NAME
: Name of the secret in AWS Secrets Manager
Contributors
- Rikwu Godwin Onyung
- Ghedinaeval Charles Don-Ibor
- Michael Fredrick Ikaka
License
ISC