Production-ready Node.js implementation with 100% feature parity with Python, Rust, Go, and TypeScript reference APIs.
A modern Node.js/Express application demonstrating infrastructure integration patterns with async/await, Promise-based concurrency, structured logging, and comprehensive observability.
- 2,161 lines of production-ready JavaScript code
- Complete infrastructure integration - All services: Vault, PostgreSQL, MySQL, MongoDB, Redis, RabbitMQ
- Modern async/await - Clean asynchronous patterns throughout
- Promise.allSettled - Concurrent health checks for all services
- Express middleware - Modular request processing with CORS, logging, error handling
- Graceful shutdown - Signal handling for clean termination
- Structured logging - Winston with correlation IDs and JSON output
- Real Prometheus metrics - HTTP request counters and latency histograms
- Helmet security - HTTP security headers
- Comprehensive health checks - 8 health endpoints monitoring infrastructure
- Features
- Quick Start
- API Endpoints
- Architecture
- Key Integration Patterns
- Environment Variables
- Development
- Comparison with Other Implementations
- What This Demonstrates
- What This Is NOT
- Security Notes
- Documentation Links
- Quick Examples
- Summary
A Node.js/Express application demonstrating infrastructure integration patterns with the DevStack Core stack.
- Vault Integration: Secure credential fetching using node-vault
- Database Connections: PostgreSQL, MySQL, MongoDB with Vault credentials
- Caching: Redis cluster operations with TTL support
- Messaging: RabbitMQ message publishing
- Health Monitoring: Comprehensive health checks for all services
- Observability: Prometheus metrics, structured logging with Winston
- Security: Helmet, CORS, request ID correlation
- Rate Limiting: IP-based rate limiting with configurable limits (default 100/min, strict 10/min, high 1000/min)
- Request Validation: Field presence, type checking, and constraint validation middleware
- Async/Await: Modern asynchronous patterns throughout
- Promise.allSettled: Concurrent health checks
- Express Middleware: Modular request processing
- Graceful Shutdown: Signal handling for clean termination
- Structured Logging: JSON logging with correlation IDs
# Start the Node.js reference API
docker compose up -d nodejs-api
# Verify it's running
curl http://localhost:8003/
# Check infrastructure health
curl http://localhost:8003/health/all
# Test Vault integration
curl http://localhost:8003/examples/vault/secret/postgresGET /- API information and endpoint listing
GET /health/- Simple health check (no dependencies)GET /health/all- Aggregate health of all services (concurrent checks)GET /health/vault- Vault connectivity and statusGET /health/postgres- PostgreSQL connection testGET /health/mysql- MySQL connection testGET /health/mongodb- MongoDB connection testGET /health/redis- Redis cluster healthGET /health/rabbitmq- RabbitMQ connectivity
GET /examples/vault/secret/:serviceName- Fetch all secrets for a serviceGET /examples/vault/secret/:serviceName/:key- Fetch specific secret key
GET /examples/database/postgres/query- PostgreSQL query exampleGET /examples/database/mysql/query- MySQL query exampleGET /examples/database/mongodb/query- MongoDB query example
GET /examples/cache/:key- Get cached valuePOST /examples/cache/:key- Set cached value (with optional TTL)DELETE /examples/cache/:key- Delete cached value
POST /examples/messaging/publish/:queue- Publish message to RabbitMQ queue
GET /metrics- Prometheus metrics endpoint
reference-apps/nodejs/
├── src/
│ ├── index.js # Application entry point
│ ├── config.js # Environment configuration
│ ├── routes/ # API endpoints
│ │ ├── health.js # Health checks
│ │ ├── vault.js # Vault integration examples
│ │ ├── database.js # Database examples
│ │ ├── cache.js # Redis caching
│ │ └── messaging.js # RabbitMQ messaging
│ ├── services/ # Reusable clients
│ │ └── vault.js # Vault client wrapper
│ └── middleware/ # Express middleware
│ ├── logging.js # Request logging with correlation IDs
│ ├── cors.js # CORS configuration
│ ├── rate-limit.js # IP-based rate limiting (100/min default)
│ └── validation.js # Request validation middleware
├── tests/ # Test suite
├── Dockerfile # Container build
├── package.json # Dependencies
└── README.md # This file
const { vaultClient } = require('./services/vault');
// Get all credentials for a service
const creds = await vaultClient.getSecret('postgres');
const { user, password, database } = creds;
// Get a specific key
const password = await vaultClient.getSecretKey('postgres', 'password');const { Client } = require('pg');
const { vaultClient } = require('./services/vault');
// Fetch credentials from Vault
const creds = await vaultClient.getSecret('postgres');
// Connect using Vault credentials
const client = new Client({
host: 'postgres',
port: 5432,
user: creds.user,
password: creds.password,
database: creds.database
});
await client.connect();
const result = await client.query('SELECT NOW()');
await client.end();const { createClient } = require('redis');
const { vaultClient } = require('./services/vault');
// Get Redis credentials
const creds = await vaultClient.getSecret('redis-1');
// Connect to Redis
const client = createClient({
socket: { host: 'redis-1', port: 6379 },
password: creds.password
});
await client.connect();
// Use cache
await client.setEx('key', 60, 'value'); // Set with 60s TTL
const value = await client.get('key');
await client.quit();| Variable | Default | Description |
|---|---|---|
HTTP_PORT |
8003 |
HTTP server port |
HTTPS_PORT |
8446 |
HTTPS server port (when TLS enabled) |
NODE_ENV |
development |
Environment (development/production) |
DEBUG |
true |
Enable debug logging |
VAULT_ADDR |
http://vault:8200 |
Vault server address |
VAULT_TOKEN |
- | Vault authentication token |
POSTGRES_HOST |
postgres |
PostgreSQL hostname |
MYSQL_HOST |
mysql |
MySQL hostname |
MONGODB_HOST |
mongodb |
MongoDB hostname |
REDIS_HOST |
redis-1 |
Redis hostname |
RABBITMQ_HOST |
rabbitmq |
RabbitMQ hostname |
# Install dependencies
cd reference-apps/nodejs
npm install
# Run locally (requires infrastructure running)
export VAULT_TOKEN=$(cat ~/.config/vault/token)
npm start
# Development mode with auto-reload
npm run dev# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Run with coverage
npm test -- --coverage| Feature | Python (FastAPI) | Go (Gin) | Node.js (Express) |
|---|---|---|---|
| Port | 8000/8001 | 8002 | 8003 |
| Async Model | async/await | goroutines | async/await, Promises |
| Concurrency | asyncio | native goroutines | Promise.allSettled |
| Vault Client | hvac | hashicorp/vault | node-vault |
| PostgreSQL | asyncpg | pgx | pg |
| Redis | redis-py | go-redis | redis (node) |
| Logging | Python logging | logrus | winston |
| Metrics | prometheus_client | prometheus/client_golang | prom-client |
✅ Secrets Management - Vault integration for dynamic credentials ✅ Database Integration - PostgreSQL, MySQL, MongoDB with Vault ✅ Caching Patterns - Redis cluster operations ✅ Message Queuing - RabbitMQ publishing ✅ Health Monitoring - Comprehensive service health checks ✅ Observability - Structured logging and Prometheus metrics ✅ Node.js Best Practices - Modern async patterns, middleware, error handling
❌ Not production-ready - Reference implementation for learning, not hardened for production ❌ Not feature-complete - Focuses on integration patterns, not business logic ❌ Not optimized - Simple implementations for learning ❌ Not secure - Uses root Vault token for simplicity
For learning only:
⚠️ Uses Vault root token (use AppRole in production)⚠️ No authentication/authorization on endpoints⚠️ Limited input validation⚠️ Debug mode enabled
- Main README: ../../README.md
- Reference Apps Overview: ../README.md
- API Patterns: ../API_PATTERNS.md
- CHANGELOG: ../CHANGELOG.md
curl http://localhost:8003/health/all | jq '.services'curl http://localhost:8003/examples/vault/secret/postgres | jq '.data'curl http://localhost:8003/examples/database/postgres/query | jq '.'# Set a value with 60s TTL
curl -X POST http://localhost:8003/examples/cache/mykey \
-H "Content-Type: application/json" \
-d '{"value": "hello", "ttl": 60}'
# Get the value
curl http://localhost:8003/examples/cache/mykey | jq '.'
# Delete the value
curl -X DELETE http://localhost:8003/examples/cache/mykey | jq '.'curl -X POST http://localhost:8003/examples/messaging/publish/test-queue \
-H "Content-Type: application/json" \
-d '{"message": "Hello from Node.js!"}'This Node.js reference implementation demonstrates:
- 📚 Modern JavaScript/Node.js patterns for infrastructure integration
- 🔍 How to integrate Express applications with Vault, databases, caching, and messaging
- 🚀 Async/await patterns for clean asynchronous code
- ✅ Comprehensive health monitoring and observability
Remember: This is a learning resource. Use these patterns to build your own production-ready applications with proper security, monitoring, and error handling.