- Copy
.env.exampleto.env - Set
ENCRYPTION_KEYto a secure 32+ character value - Configure
DB_HOST,DB_PORT,DB_USER,DB_PASSWORD - Set
SERVICE_PORT(default: 3020) - Set
NODE_ENV(development/staging/production) - Configure
CACHE_TTL(default: 3600 seconds)
- PostgreSQL 12+ installed
- Database created (
config_dbby default) - Database user has proper permissions
- Test connection from the service host
- Node.js 18+ installed
- npm or yarn installed
- Run
npm installto install dependencies - Verify no security vulnerabilities:
npm audit
- Run
npm run buildsuccessfully - No TypeScript compilation errors
-
dist/directory created
- Run
npm test- all unit tests pass - Run
npm run test:e2e- all E2E tests pass - Code coverage acceptable:
npm run test:cov
- Run
npm run lint:check- no errors - Run
npm run format:check- formatted correctly - Run
npm run type-check- no type errors
# 1. Navigate to service directory
cd microservices/config-service
# 2. Create environment file
cp .env.example .env
# 3. Update important .env variables:
# ENCRYPTION_KEY=your-secure-key-32-chars-minimum
# DB_HOST=postgres (for docker network)
# SERVICE_PORT=3020
# 4. Start services
docker-compose up -d
# 5. Wait for services to start (10-15 seconds)
# 6. Check health
curl http://localhost:3020/health
# 7. View logs
docker-compose logs -f config-service# 1. Navigate to service directory
cd microservices/config-service
# 2. Install dependencies
npm install
# 3. Create environment file
cp .env.example .env
# 4. Update .env with your local database details
# DB_HOST=localhost
# DB_PORT=5432
# DB_NAME=config_db
# DB_USER=postgres
# DB_PASSWORD=your-password
# 5. Run database migrations
npm run migration:run
# 6. Start in development mode
npm run start:dev
# 7. Service will be available at http://localhost:3020# Development
curl -X POST http://localhost:3020/environments \
-H "Content-Type: application/json" \
-d '{
"name": "development",
"displayName": "Development",
"description": "Development environment"
}'
# Staging
curl -X POST http://localhost:3020/environments \
-H "Content-Type: application/json" \
-d '{
"name": "staging",
"displayName": "Staging",
"description": "Staging environment"
}'
# Production
curl -X POST http://localhost:3020/environments \
-H "Content-Type: application/json" \
-d '{
"name": "production",
"displayName": "Production",
"description": "Production environment"
}'# Example: Log level
curl -X POST http://localhost:3020/configurations \
-H "Content-Type: application/json" \
-d '{
"key": "LOG_LEVEL",
"value": "info",
"type": "string",
"description": "Application log level",
"category": "app"
}'
# Example: Debug mode
curl -X POST http://localhost:3020/configurations \
-H "Content-Type: application/json" \
-d '{
"key": "DEBUG_MODE",
"value": "false",
"type": "boolean",
"description": "Enable debug mode",
"category": "app"
}'# Database password
curl -X POST http://localhost:3020/secrets \
-H "Content-Type: application/json" \
-d '{
"name": "DB_PASSWORD",
"value": "super-secret-password",
"description": "Database password",
"rotationIntervalSeconds": 7776000
}'
# API keys
curl -X POST http://localhost:3020/secrets \
-H "Content-Type: application/json" \
-d '{
"name": "API_KEY",
"value": "your-api-key-here",
"description": "External API key",
"category": "external"
}'# Subscribe payment service
curl -X POST http://localhost:3020/webhooks \
-H "Content-Type: application/json" \
-d '{
"serviceName": "payment-service",
"webhookUrl": "http://payment-service:3019/webhooks/config-update",
"events": ["CONFIG_CREATED", "CONFIG_UPDATED"],
"secret": "payment-webhook-secret"
}'
# Subscribe user service
curl -X POST http://localhost:3020/webhooks \
-H "Content-Type: application/json" \
-d '{
"serviceName": "user-service",
"webhookUrl": "http://user-service:3001/webhooks/config-update",
"events": ["CONFIG_CREATED", "CONFIG_UPDATED"],
"secret": "user-webhook-secret"
}'curl http://localhost:3020/health
# Expected: {"status":"OK","service":"config-service","timestamp":"..."}curl http://localhost:3020/
# Expected: Service information with available endpointsOpen in browser: http://localhost:3020/api
- Swagger UI with all available endpoints
# Check if tables exist (from PostgreSQL client)
\dt
# Should see: configurations, environments, secrets, audit_logs, webhook_subscriptionscurl http://localhost:3020/configurations
# Should return array of configurationscurl http://localhost:3020/secrets
# Should return array of secret metadata (values encrypted)curl http://localhost:3020/audit-logs
# Should show creation events from previous stepsSolution: Change SERVICE_PORT in .env or kill process using port 3020
Steps:
- Check PostgreSQL is running
- Verify connection string in
.env - Ensure database exists
- Test connection:
psql -h localhost -U postgres -d config_db
Steps:
- Drop tables:
DROP TABLE IF EXISTS ...; - Run migration again:
npm run migration:run - Check migration status:
npm run migration:show(if available)
Steps:
- Check
ENCRYPTION_KEYlength (minimum 32 characters) - Use only alphanumeric characters
- Update
.envand restart service
Steps:
- Verify webhook URL is accessible
- Check webhook logs for errors
- Increase
retryAttemptsandretryDelayMsin webhook config - Verify signature if using
secret
Steps:
- Clear cache:
curl -X POST http://localhost:3020/clear-cache - Or restart service (cache is in-memory)
CACHE_TTL=3600 # 1 hour cache validity
CACHE_MAX_SIZE=1000 # Maximum items in cacheAdjust in app.module.ts if needed:
// maxConnections, idleTimeoutMillis, etc.RETRY_ATTEMPTS=3
RETRY_DELAY_MS=5000 # 5 seconds between retries- ENCRYPTION_KEY is strong (32+ random characters)
- Database password is strong
- Webhook secrets are configured
- CORS is configured properly
- Environment variables are not committed to git
- .env file is in .gitignore
- Database user has minimal required permissions
- SSL/TLS configured for production
- Audit logs are monitored
- Secret rotation is tested
- Check audit logs daily for unusual activity
- Monitor secret rotation schedule
- Verify webhook delivery success
- Check database size and backups
- Review application logs
# View recent audit logs
curl http://localhost:3020/audit-logs?limit=100
# Check secrets needing rotation
curl http://localhost:3020/secrets/rotation/pending
# Check webhook status
curl http://localhost:3020/webhooks
# View application metrics (if enabled)
curl http://localhost:3020/metrics-
Read the Documentation
microservices/config-service/README.md- Complete guideCONFIG_SERVICE_INTEGRATION.md- How to use from other services
-
API Documentation
- Available at
http://localhost:3020/api(Swagger UI)
- Available at
-
Source Code
- Well-commented code in
src/directory - Examples in
test/directory
- Well-commented code in
-
Database Schema
- Check schema at
src/entities/ - Migrations tracked in database
- Check schema at
Before deploying to production, ensure:
- All environment variables configured
- Database backups enabled
- SSL/TLS certificates installed
- Monitoring and alerting set up
- Disaster recovery plan in place
- Team trained on service usage
- Documentation accessible to team
- Security audit completed
- Load testing performed
- Rollback plan documented
The Config Service is now ready for:
- β Development use
- β Integration testing
- β Staging deployment
- β Production deployment
Next: Follow the integration guide to connect other services to this config service.
For detailed information, see CONFIG_SERVICE_INTEGRATION.md