UNPKG

@misterzik/espressojs

Version:

EspressoJS Introducing Espresso.JS, your ultimate Express configuration starting point and boilerplate. With its simplicity and lack of opinionation, EspressoJS offers plug-and-play configurations built on top of Express.

263 lines (206 loc) • 7.33 kB
# EspressoJS v3.3.0 - Enhancement Summary This document outlines all the major enhancements made to modernize the EspressoJS framework. ## šŸŽÆ Overview EspressoJS has been upgraded from a basic Express boilerplate to a **production-ready, enterprise-grade framework** with modern security, logging, error handling, and developer experience improvements. ## šŸ” Security Enhancements ### Helmet.js Integration - **Location**: `server/middleware/security.js` - **Features**: - Content Security Policy (CSP) - XSS Protection - HSTS headers - Frame protection - Cross-origin policies ### Rate Limiting - **General Rate Limit**: 100 requests per 15 minutes - **API Rate Limit**: 200 requests per 15 minutes - **Strict Rate Limit**: 10 requests per 15 minutes (for sensitive endpoints) - Configurable per-route rate limiting ### Enhanced CORS - Pre-configured CORS middleware - Customizable origin policies - Credential support ## šŸ“ Logging System ### Winston Logger - **Location**: `server/utils/logger.js` - **Features**: - Multiple log levels (error, warn, info, http, debug) - Color-coded console output - File-based logging with rotation - Exception and rejection handlers ### Log Files - `logs/combined.log` - All application logs - `logs/error.log` - Error logs only - `logs/exceptions.log` - Uncaught exceptions - `logs/rejections.log` - Unhandled promise rejections ### Morgan Integration - HTTP request logging - Environment-specific formats (dev/combined) - Integrated with Winston logger ## šŸ›”ļø Error Handling ### Centralized Error Handler - **Location**: `server/middleware/errorHandler.js` - **Components**: - `AppError` class for operational errors - `errorHandler` middleware for global error handling - `notFoundHandler` for 404 errors - `asyncHandler` wrapper for async routes ### Features - Environment-specific error responses - Stack traces in development - Sanitized errors in production - Proper HTTP status codes ## šŸ„ Health Monitoring ### Health Check Endpoints - **Location**: `server/middleware/healthCheck.js` #### `/health` Comprehensive health check with: - Server uptime - Memory usage - CPU metrics - Database connection status - Environment information #### `/ready` Readiness probe for orchestration platforms (Kubernetes, Docker Swarm) #### `/alive` Liveness probe for monitoring systems ## šŸ”§ Configuration Management ### Joi Validation - **Location**: `server/utils/configValidator.js` - Schema-based configuration validation - Type checking and constraints - Default value handling - Detailed error messages ### Enhanced Config Utils - **Location**: `server/utils/config.utils.js` - Safe file reading with error handling - Default configuration fallback - Validated writes - Better error messages ## šŸŽ® CLI Improvements ### New Commands - **Location**: `server/utils/espresso-cli.js` | Command | Description | |---------|-------------| | `init` | Initialize new config.json | | `validate` | Validate configuration | | `version` | Show version information | | `show` | Display current config (enhanced) | | `run` | Run server (improved) | | `env` | Update environment (enhanced) | ### Features - Better error messages with āœ“/āœ— indicators - Improved command help system - Spawn-based process management - Proper exit codes - Input validation ## šŸš€ Application Improvements ### Main Application (`index.js`) - Graceful shutdown handling (SIGTERM, SIGINT) - Proper resource cleanup - Enhanced startup banner - Better error handling - Request body size limits (10MB) - Improved MongoDB connection handling ### Routes Enhancement - **Location**: `routes/index.js` - Async error handling - Safe file operations - Better error messages - Graceful route loading failures - Default JSON responses ## šŸ“¦ Dependency Updates ### New Dependencies ```json { "helmet": "^7.1.0", "morgan": "^1.10.0", "winston": "^3.11.0", "express-rate-limit": "^7.1.5", "express-validator": "^7.0.1", "joi": "^17.11.0" } ``` ### Updated Dependencies - `axios`: ^1.4.0 → ^1.6.0 - `mongoose`: ^7.3.1 → ^8.0.3 ## šŸ“š Documentation ### New Documentation Files - `README.md` - Comprehensive documentation (completely rewritten) - `QUICKSTART.md` - 5-minute quick start guide - `CHANGELOG.md` - Version history and changes - `CONTRIBUTING.md` - Contribution guidelines - `ENHANCEMENTS.md` - This file ### Example Files - `examples/basic-api.js` - REST API examples - `examples/mongodb-example.js` - MongoDB integration - `examples/README.md` - Examples documentation ## šŸŽØ Developer Experience ### Improved Startup ``` ╔═══════════════════════════════════════════════════════╗ ā•‘ ESPRESSO.JS ā•‘ ā•‘ Express Boilerplate Server ā•‘ ╠═══════════════════════════════════════════════════════╣ ā•‘ Environment: development ā•‘ ā•‘ Port: 8080 ā•‘ ā•‘ URL: http://localhost:8080 ā•‘ ā•‘ MongoDB: Disabled ā•‘ ā•‘ API: Disabled ā•‘ ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā• ``` ### Better Error Messages - Descriptive validation errors - Helpful CLI feedback - Color-coded console output - Stack traces in development ## šŸ”„ Breaking Changes ### None! All changes are backward compatible. Existing EspressoJS projects will continue to work without modifications. ## šŸ“Š Performance Improvements - Compression enabled by default - Static file caching (1 day max-age) - ETags enabled - Request size limits prevent memory issues - Efficient logging with Winston ## šŸ› ļø Migration Guide ### From v3.2.6 to v3.3.0 1. **Update dependencies**: ```bash npm install ``` 2. **Optional: Use new CLI commands**: ```bash node cli validate # Check your config node cli version # See version info ``` 3. **Optional: Add health checks to monitoring**: - Add `/health` to your monitoring system - Use `/ready` and `/alive` for orchestration 4. **Optional: Use new middleware**: ```javascript const { asyncHandler, AppError } = require('./server/middleware/errorHandler'); const logger = require('./server/utils/logger'); ``` ## šŸŽÆ Future Roadmap Potential future enhancements: - TypeScript support - WebSocket integration - GraphQL support - Built-in testing framework - Docker configuration - CI/CD templates - Swagger/OpenAPI documentation - Redis caching support - Session management - Authentication middleware ## šŸ™ Acknowledgments Built with modern Express.js best practices and inspired by production-grade Node.js applications. ## šŸ“ž Support - GitHub: https://github.com/misterzik/Espresso.js - Issues: https://github.com/misterzik/Espresso.js/issues - npm: https://www.npmjs.com/package/@misterzik/espressojs --- **Version**: 3.3.0 **Release Date**: 2024 **License**: MIT