@misterzik/espressojs 3.2.5 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,115 @@
1
+ # Changelog
2
+
3
+ All notable changes to EspressoJS will be documented in this file.
4
+
5
+ ## [3.3.1] - 2024-01-01
6
+
7
+ ### Added
8
+ - **Multiple API Endpoints Support**
9
+ - Configure unlimited API endpoints using `api`, `api2`, `api3`, etc. pattern
10
+ - New `APIManager` class for managing multiple APIs
11
+ - Support for per-API timeout and retry configuration
12
+ - Automatic retry with exponential backoff
13
+ - API health checking and fallback patterns
14
+ - Comprehensive documentation in `docs/MULTIPLE-APIS.md`
15
+ - Example implementation in `examples/multiple-apis.js`
16
+
17
+ - **Configuration Enhancements**
18
+ - Added `publicDirectory` option to customize static files location
19
+ - Added `timeout` option for API requests (default: 30000ms)
20
+ - Added `retries` option for automatic retry (0-5 attempts)
21
+ - Support for HEAD and OPTIONS HTTP methods
22
+ - Unknown configuration keys now allowed for flexibility
23
+
24
+ - **API Manager Features**
25
+ - `request(apiName, endpoint, options)` - Make API requests
26
+ - `getAPI(name)` - Get specific API configuration
27
+ - `getAllAPIs()` - List all configured APIs
28
+ - `hasAPI(name)` - Check API availability
29
+ - `createAxiosInstance(apiName)` - Create custom Axios client
30
+
31
+ ### Changed
32
+ - Configuration validator now supports dynamic API endpoints
33
+ - Static file serving now uses `publicDirectory` from config
34
+ - Exported `apiManager` and `config` from main module
35
+
36
+ ### Fixed
37
+ - Configuration validation now properly handles multiple API endpoints
38
+ - Better error messages for API configuration issues
39
+
40
+ ## [3.3.0] - 2024-01-01
41
+
42
+ ### Added
43
+ - **Security Enhancements**
44
+ - Helmet.js integration for secure HTTP headers
45
+ - Express rate limiting to prevent abuse
46
+ - Enhanced CORS configuration
47
+ - Content Security Policy (CSP) headers
48
+
49
+ - **Advanced Logging**
50
+ - Winston logger with multiple transports
51
+ - File-based logging (combined, error, exceptions, rejections)
52
+ - Colored console output
53
+ - HTTP request logging with Morgan
54
+
55
+ - **Error Handling**
56
+ - Centralized error handling middleware
57
+ - Custom AppError class for operational errors
58
+ - Async error handler wrapper
59
+ - 404 not found handler
60
+ - Graceful error responses
61
+
62
+ - **Health Monitoring**
63
+ - `/health` endpoint with system metrics
64
+ - `/ready` readiness probe
65
+ - `/alive` liveness probe
66
+ - Memory and CPU usage reporting
67
+ - Database connection status
68
+
69
+ - **Configuration Management**
70
+ - Joi-based configuration validation
71
+ - Default configuration fallback
72
+ - Enhanced error handling for config files
73
+ - Environment variable validation
74
+
75
+ - **CLI Improvements**
76
+ - `init` command to create config.json
77
+ - `validate` command to check configuration
78
+ - `version` command for version info
79
+ - Better error messages and formatting
80
+ - Command help system
81
+
82
+ - **Graceful Shutdown**
83
+ - SIGTERM and SIGINT handling
84
+ - Proper cleanup of MongoDB connections
85
+ - HTTP server graceful close
86
+ - Timeout-based forced shutdown
87
+
88
+ - **Developer Experience**
89
+ - Better startup banner with configuration info
90
+ - Improved error messages
91
+ - Enhanced documentation
92
+ - Request body size limits (10mb)
93
+
94
+ ### Changed
95
+ - Updated dependencies to latest versions
96
+ - Improved MongoDB connection handling
97
+ - Enhanced route loading with error handling
98
+ - Better default responses for missing files
99
+ - Modernized CLI with spawn instead of exec
100
+
101
+ ### Fixed
102
+ - Configuration file reading errors
103
+ - MongoDB connection error handling
104
+ - Route loading failures
105
+ - Missing file handling
106
+
107
+ ## [3.2.6] - 2023-07-01
108
+
109
+ ### Initial Release
110
+ - Basic Express server setup
111
+ - MongoDB integration
112
+ - Configuration management
113
+ - CLI tools
114
+ - Static file serving
115
+ - CORS and compression support
@@ -0,0 +1,96 @@
1
+ # Contributing to EspressoJS
2
+
3
+ Thank you for considering contributing to EspressoJS! This document provides guidelines and instructions for contributing.
4
+
5
+ ## Code of Conduct
6
+
7
+ - Be respectful and inclusive
8
+ - Provide constructive feedback
9
+ - Focus on what is best for the community
10
+ - Show empathy towards other community members
11
+
12
+ ## How to Contribute
13
+
14
+ ### Reporting Bugs
15
+
16
+ Before creating bug reports, please check existing issues. When creating a bug report, include:
17
+
18
+ - **Clear title and description**
19
+ - **Steps to reproduce** the behavior
20
+ - **Expected behavior**
21
+ - **Actual behavior**
22
+ - **Environment details** (OS, Node version, npm version)
23
+ - **Code samples** if applicable
24
+
25
+ ### Suggesting Enhancements
26
+
27
+ Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion, include:
28
+
29
+ - **Clear title and description**
30
+ - **Use case** for the enhancement
31
+ - **Proposed solution** or implementation
32
+ - **Alternative solutions** you've considered
33
+
34
+ ### Pull Requests
35
+
36
+ 1. Fork the repository
37
+ 2. Create a new branch (`git checkout -b feature/amazing-feature`)
38
+ 3. Make your changes
39
+ 4. Commit your changes (`git commit -m 'Add amazing feature'`)
40
+ 5. Push to the branch (`git push origin feature/amazing-feature`)
41
+ 6. Open a Pull Request
42
+
43
+ #### Pull Request Guidelines
44
+
45
+ - Follow the existing code style
46
+ - Update documentation as needed
47
+ - Add tests if applicable
48
+ - Ensure all tests pass
49
+ - Keep commits atomic and well-described
50
+ - Reference related issues in PR description
51
+
52
+ ## Development Setup
53
+
54
+ ```bash
55
+ # Clone the repository
56
+ git clone https://github.com/misterzik/Espresso.js.git
57
+ cd Espresso.js
58
+
59
+ # Install dependencies
60
+ npm install
61
+
62
+ # Run in development mode
63
+ npm run dev
64
+ ```
65
+
66
+ ## Code Style
67
+
68
+ - Use 2 spaces for indentation
69
+ - Use semicolons
70
+ - Use single quotes for strings
71
+ - Add comments for complex logic
72
+ - Follow existing patterns in the codebase
73
+
74
+ ## Testing
75
+
76
+ Before submitting a PR, ensure:
77
+
78
+ - Code follows the style guide
79
+ - All existing tests pass
80
+ - New features include tests
81
+ - Documentation is updated
82
+
83
+ ## Commit Messages
84
+
85
+ - Use present tense ("Add feature" not "Added feature")
86
+ - Use imperative mood ("Move cursor to..." not "Moves cursor to...")
87
+ - Limit first line to 72 characters
88
+ - Reference issues and PRs when applicable
89
+
90
+ ## Questions?
91
+
92
+ Feel free to open an issue with your question or reach out to the maintainers.
93
+
94
+ ## License
95
+
96
+ By contributing, you agree that your contributions will be licensed under the MIT License.
@@ -0,0 +1,262 @@
1
+ # EspressoJS v3.3.0 - Enhancement Summary
2
+
3
+ This document outlines all the major enhancements made to modernize the EspressoJS framework.
4
+
5
+ ## 🎯 Overview
6
+
7
+ 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.
8
+
9
+ ## 🔐 Security Enhancements
10
+
11
+ ### Helmet.js Integration
12
+ - **Location**: `server/middleware/security.js`
13
+ - **Features**:
14
+ - Content Security Policy (CSP)
15
+ - XSS Protection
16
+ - HSTS headers
17
+ - Frame protection
18
+ - Cross-origin policies
19
+
20
+ ### Rate Limiting
21
+ - **General Rate Limit**: 100 requests per 15 minutes
22
+ - **API Rate Limit**: 200 requests per 15 minutes
23
+ - **Strict Rate Limit**: 10 requests per 15 minutes (for sensitive endpoints)
24
+ - Configurable per-route rate limiting
25
+
26
+ ### Enhanced CORS
27
+ - Pre-configured CORS middleware
28
+ - Customizable origin policies
29
+ - Credential support
30
+
31
+ ## 📝 Logging System
32
+
33
+ ### Winston Logger
34
+ - **Location**: `server/utils/logger.js`
35
+ - **Features**:
36
+ - Multiple log levels (error, warn, info, http, debug)
37
+ - Color-coded console output
38
+ - File-based logging with rotation
39
+ - Exception and rejection handlers
40
+
41
+ ### Log Files
42
+ - `logs/combined.log` - All application logs
43
+ - `logs/error.log` - Error logs only
44
+ - `logs/exceptions.log` - Uncaught exceptions
45
+ - `logs/rejections.log` - Unhandled promise rejections
46
+
47
+ ### Morgan Integration
48
+ - HTTP request logging
49
+ - Environment-specific formats (dev/combined)
50
+ - Integrated with Winston logger
51
+
52
+ ## 🛡️ Error Handling
53
+
54
+ ### Centralized Error Handler
55
+ - **Location**: `server/middleware/errorHandler.js`
56
+ - **Components**:
57
+ - `AppError` class for operational errors
58
+ - `errorHandler` middleware for global error handling
59
+ - `notFoundHandler` for 404 errors
60
+ - `asyncHandler` wrapper for async routes
61
+
62
+ ### Features
63
+ - Environment-specific error responses
64
+ - Stack traces in development
65
+ - Sanitized errors in production
66
+ - Proper HTTP status codes
67
+
68
+ ## 🏥 Health Monitoring
69
+
70
+ ### Health Check Endpoints
71
+ - **Location**: `server/middleware/healthCheck.js`
72
+
73
+ #### `/health`
74
+ Comprehensive health check with:
75
+ - Server uptime
76
+ - Memory usage
77
+ - CPU metrics
78
+ - Database connection status
79
+ - Environment information
80
+
81
+ #### `/ready`
82
+ Readiness probe for orchestration platforms (Kubernetes, Docker Swarm)
83
+
84
+ #### `/alive`
85
+ Liveness probe for monitoring systems
86
+
87
+ ## 🔧 Configuration Management
88
+
89
+ ### Joi Validation
90
+ - **Location**: `server/utils/configValidator.js`
91
+ - Schema-based configuration validation
92
+ - Type checking and constraints
93
+ - Default value handling
94
+ - Detailed error messages
95
+
96
+ ### Enhanced Config Utils
97
+ - **Location**: `server/utils/config.utils.js`
98
+ - Safe file reading with error handling
99
+ - Default configuration fallback
100
+ - Validated writes
101
+ - Better error messages
102
+
103
+ ## 🎮 CLI Improvements
104
+
105
+ ### New Commands
106
+ - **Location**: `server/utils/espresso-cli.js`
107
+
108
+ | Command | Description |
109
+ |---------|-------------|
110
+ | `init` | Initialize new config.json |
111
+ | `validate` | Validate configuration |
112
+ | `version` | Show version information |
113
+ | `show` | Display current config (enhanced) |
114
+ | `run` | Run server (improved) |
115
+ | `env` | Update environment (enhanced) |
116
+
117
+ ### Features
118
+ - Better error messages with ✓/✗ indicators
119
+ - Improved command help system
120
+ - Spawn-based process management
121
+ - Proper exit codes
122
+ - Input validation
123
+
124
+ ## 🚀 Application Improvements
125
+
126
+ ### Main Application (`index.js`)
127
+ - Graceful shutdown handling (SIGTERM, SIGINT)
128
+ - Proper resource cleanup
129
+ - Enhanced startup banner
130
+ - Better error handling
131
+ - Request body size limits (10MB)
132
+ - Improved MongoDB connection handling
133
+
134
+ ### Routes Enhancement
135
+ - **Location**: `routes/index.js`
136
+ - Async error handling
137
+ - Safe file operations
138
+ - Better error messages
139
+ - Graceful route loading failures
140
+ - Default JSON responses
141
+
142
+ ## 📦 Dependency Updates
143
+
144
+ ### New Dependencies
145
+ ```json
146
+ {
147
+ "helmet": "^7.1.0",
148
+ "morgan": "^1.10.0",
149
+ "winston": "^3.11.0",
150
+ "express-rate-limit": "^7.1.5",
151
+ "express-validator": "^7.0.1",
152
+ "joi": "^17.11.0"
153
+ }
154
+ ```
155
+
156
+ ### Updated Dependencies
157
+ - `axios`: ^1.4.0 → ^1.6.0
158
+ - `mongoose`: ^7.3.1 → ^8.0.3
159
+
160
+ ## 📚 Documentation
161
+
162
+ ### New Documentation Files
163
+ - `README.md` - Comprehensive documentation (completely rewritten)
164
+ - `QUICKSTART.md` - 5-minute quick start guide
165
+ - `CHANGELOG.md` - Version history and changes
166
+ - `CONTRIBUTING.md` - Contribution guidelines
167
+ - `ENHANCEMENTS.md` - This file
168
+
169
+ ### Example Files
170
+ - `examples/basic-api.js` - REST API examples
171
+ - `examples/mongodb-example.js` - MongoDB integration
172
+ - `examples/README.md` - Examples documentation
173
+
174
+ ## 🎨 Developer Experience
175
+
176
+ ### Improved Startup
177
+ ```
178
+ ╔═══════════════════════════════════════════════════════╗
179
+ ║ ESPRESSO.JS ║
180
+ ║ Express Boilerplate Server ║
181
+ ╠═══════════════════════════════════════════════════════╣
182
+ ║ Environment: development ║
183
+ ║ Port: 8080 ║
184
+ ║ URL: http://localhost:8080 ║
185
+ ║ MongoDB: Disabled ║
186
+ ║ API: Disabled ║
187
+ ╚═══════════════════════════════════════════════════════╝
188
+ ```
189
+
190
+ ### Better Error Messages
191
+ - Descriptive validation errors
192
+ - Helpful CLI feedback
193
+ - Color-coded console output
194
+ - Stack traces in development
195
+
196
+ ## 🔄 Breaking Changes
197
+
198
+ ### None!
199
+ All changes are backward compatible. Existing EspressoJS projects will continue to work without modifications.
200
+
201
+ ## 📊 Performance Improvements
202
+
203
+ - Compression enabled by default
204
+ - Static file caching (1 day max-age)
205
+ - ETags enabled
206
+ - Request size limits prevent memory issues
207
+ - Efficient logging with Winston
208
+
209
+ ## 🛠️ Migration Guide
210
+
211
+ ### From v3.2.6 to v3.3.0
212
+
213
+ 1. **Update dependencies**:
214
+ ```bash
215
+ npm install
216
+ ```
217
+
218
+ 2. **Optional: Use new CLI commands**:
219
+ ```bash
220
+ node cli validate # Check your config
221
+ node cli version # See version info
222
+ ```
223
+
224
+ 3. **Optional: Add health checks to monitoring**:
225
+ - Add `/health` to your monitoring system
226
+ - Use `/ready` and `/alive` for orchestration
227
+
228
+ 4. **Optional: Use new middleware**:
229
+ ```javascript
230
+ const { asyncHandler, AppError } = require('./server/middleware/errorHandler');
231
+ const logger = require('./server/utils/logger');
232
+ ```
233
+
234
+ ## 🎯 Future Roadmap
235
+
236
+ Potential future enhancements:
237
+ - TypeScript support
238
+ - WebSocket integration
239
+ - GraphQL support
240
+ - Built-in testing framework
241
+ - Docker configuration
242
+ - CI/CD templates
243
+ - Swagger/OpenAPI documentation
244
+ - Redis caching support
245
+ - Session management
246
+ - Authentication middleware
247
+
248
+ ## 🙏 Acknowledgments
249
+
250
+ Built with modern Express.js best practices and inspired by production-grade Node.js applications.
251
+
252
+ ## 📞 Support
253
+
254
+ - GitHub: https://github.com/misterzik/Espresso.js
255
+ - Issues: https://github.com/misterzik/Espresso.js/issues
256
+ - npm: https://www.npmjs.com/package/@misterzik/espressojs
257
+
258
+ ---
259
+
260
+ **Version**: 3.3.0
261
+ **Release Date**: 2024
262
+ **License**: MIT
package/MIGRATION.md ADDED
@@ -0,0 +1,204 @@
1
+ # Migration Guide
2
+
3
+ This guide helps you upgrade your EspressoJS application to the latest version.
4
+
5
+ ## Upgrading to v3.3.0
6
+
7
+ ### What's New?
8
+
9
+ EspressoJS v3.3.0 introduces modern security, logging, error handling, and monitoring features while maintaining **100% backward compatibility** with v3.2.6.
10
+
11
+ ### Step 1: Update Dependencies
12
+
13
+ ```bash
14
+ npm install @misterzik/espressojs@latest
15
+ ```
16
+
17
+ This will install all new dependencies automatically:
18
+ - helmet (security)
19
+ - morgan (HTTP logging)
20
+ - winston (application logging)
21
+ - express-rate-limit (rate limiting)
22
+ - express-validator (validation)
23
+ - joi (configuration validation)
24
+
25
+ ### Step 2: Verify Configuration
26
+
27
+ Your existing `config.json` will continue to work. To validate it:
28
+
29
+ ```bash
30
+ node cli validate
31
+ ```
32
+
33
+ If you see any validation errors, the CLI will guide you on how to fix them.
34
+
35
+ ### Step 3: Optional Enhancements
36
+
37
+ #### Use Health Check Endpoints
38
+
39
+ Add health monitoring to your infrastructure:
40
+
41
+ ```bash
42
+ # Check server health
43
+ curl http://localhost:8080/health
44
+
45
+ # Kubernetes readiness probe
46
+ curl http://localhost:8080/ready
47
+
48
+ # Kubernetes liveness probe
49
+ curl http://localhost:8080/alive
50
+ ```
51
+
52
+ #### Use the Logger
53
+
54
+ Replace `console.log` with the new Winston logger:
55
+
56
+ ```javascript
57
+ // Old way
58
+ console.log('Server started');
59
+ console.error('Error occurred');
60
+
61
+ // New way
62
+ const logger = require('./server/utils/logger');
63
+ logger.info('Server started');
64
+ logger.error('Error occurred');
65
+ ```
66
+
67
+ #### Use Error Handling Middleware
68
+
69
+ Wrap async routes with `asyncHandler`:
70
+
71
+ ```javascript
72
+ const { asyncHandler, AppError } = require('./server/middleware/errorHandler');
73
+
74
+ // Old way
75
+ router.get('/users/:id', async (req, res) => {
76
+ try {
77
+ const user = await User.findById(req.params.id);
78
+ res.json(user);
79
+ } catch (error) {
80
+ res.status(500).json({ error: error.message });
81
+ }
82
+ });
83
+
84
+ // New way
85
+ router.get('/users/:id', asyncHandler(async (req, res) => {
86
+ const user = await User.findById(req.params.id);
87
+ if (!user) {
88
+ throw new AppError('User not found', 404);
89
+ }
90
+ res.json(user);
91
+ }));
92
+ ```
93
+
94
+ #### Use New CLI Commands
95
+
96
+ ```bash
97
+ # Initialize new config
98
+ node cli init
99
+
100
+ # Show version
101
+ node cli version
102
+
103
+ # Validate config
104
+ node cli validate
105
+ ```
106
+
107
+ ### Step 4: Review Logs
108
+
109
+ The new logging system creates a `logs/` directory with:
110
+ - `combined.log` - All logs
111
+ - `error.log` - Errors only
112
+ - `exceptions.log` - Uncaught exceptions
113
+ - `rejections.log` - Unhandled rejections
114
+
115
+ Add `logs/` to your `.gitignore` if not already present.
116
+
117
+ ### Step 5: Update Monitoring (Optional)
118
+
119
+ If you use monitoring tools, add the new health endpoints:
120
+
121
+ **Kubernetes:**
122
+ ```yaml
123
+ livenessProbe:
124
+ httpGet:
125
+ path: /alive
126
+ port: 8080
127
+ readinessProbe:
128
+ httpGet:
129
+ path: /ready
130
+ port: 8080
131
+ ```
132
+
133
+ **Docker Compose:**
134
+ ```yaml
135
+ healthcheck:
136
+ test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
137
+ interval: 30s
138
+ timeout: 10s
139
+ retries: 3
140
+ ```
141
+
142
+ ## Breaking Changes
143
+
144
+ ### None!
145
+
146
+ All changes in v3.3.0 are backward compatible. Your existing code will continue to work without modifications.
147
+
148
+ ## New Features You Get Automatically
149
+
150
+ Even without code changes, you automatically get:
151
+
152
+ ✅ **Security**: Helmet.js protection, rate limiting, enhanced CORS
153
+ ✅ **Logging**: Winston logger with file and console output
154
+ ✅ **Error Handling**: Centralized error handling
155
+ ✅ **Health Checks**: `/health`, `/ready`, `/alive` endpoints
156
+ ✅ **Graceful Shutdown**: Proper cleanup on SIGTERM/SIGINT
157
+ ✅ **Better Startup**: Enhanced startup banner with config info
158
+ ✅ **Request Limits**: 10MB body size limit to prevent abuse
159
+
160
+ ## Troubleshooting
161
+
162
+ ### Issue: "Cannot find module 'helmet'"
163
+
164
+ **Solution**: Run `npm install` to install new dependencies.
165
+
166
+ ### Issue: Logs directory errors
167
+
168
+ **Solution**: The logs directory is created automatically. Ensure write permissions.
169
+
170
+ ### Issue: Rate limiting too strict
171
+
172
+ **Solution**: Customize rate limits in your code:
173
+
174
+ ```javascript
175
+ const { apiRateLimiter } = require('./server/middleware/security');
176
+ app.use('/api', apiRateLimiter);
177
+ ```
178
+
179
+ ### Issue: Health check returns 503
180
+
181
+ **Solution**: This is normal if MongoDB is enabled but not connected. Check your MongoDB configuration.
182
+
183
+ ## Rollback
184
+
185
+ If you need to rollback to v3.2.6:
186
+
187
+ ```bash
188
+ npm install @misterzik/espressojs@3.2.6
189
+ ```
190
+
191
+ ## Getting Help
192
+
193
+ - [GitHub Issues](https://github.com/misterzik/Espresso.js/issues)
194
+ - [Documentation](https://github.com/misterzik/Espresso.js)
195
+ - [Examples](./examples/)
196
+
197
+ ## Next Steps
198
+
199
+ 1. Review the [CHANGELOG.md](./CHANGELOG.md) for detailed changes
200
+ 2. Check out [examples/](./examples/) for code samples
201
+ 3. Read the updated [README.md](./README.md) for full documentation
202
+ 4. See [ENHANCEMENTS.md](./ENHANCEMENTS.md) for technical details
203
+
204
+ Happy upgrading! ☕