@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.
205 lines (143 loc) • 4.71 kB
Markdown
This guide helps you upgrade your EspressoJS application to the latest version.
EspressoJS v3.3.0 introduces modern security, logging, error handling, and monitoring features while maintaining **100% backward compatibility** with v3.2.6.
```bash
npm install @misterzik/espressojs@latest
```
This will install all new dependencies automatically:
- helmet (security)
- morgan (HTTP logging)
- winston (application logging)
- express-rate-limit (rate limiting)
- express-validator (validation)
- joi (configuration validation)
Your existing `config.json` will continue to work. To validate it:
```bash
node cli validate
```
If you see any validation errors, the CLI will guide you on how to fix them.
Add health monitoring to your infrastructure:
```bash
curl http://localhost:8080/health
curl http://localhost:8080/ready
curl http://localhost:8080/alive
```
Replace `console.log` with the new Winston logger:
```javascript
// Old way
console.log('Server started');
console.error('Error occurred');
// New way
const logger = require('./server/utils/logger');
logger.info('Server started');
logger.error('Error occurred');
```
Wrap async routes with `asyncHandler`:
```javascript
const { asyncHandler, AppError } = require('./server/middleware/errorHandler');
// Old way
router.get('/users/:id', async (req, res) => {
try {
const user = await User.findById(req.params.id);
res.json(user);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// New way
router.get('/users/:id', asyncHandler(async (req, res) => {
const user = await User.findById(req.params.id);
if (!user) {
throw new AppError('User not found', 404);
}
res.json(user);
}));
```
```bash
node cli init
node cli version
node cli validate
```
The new logging system creates a `logs/` directory with:
- `combined.log` - All logs
- `error.log` - Errors only
- `exceptions.log` - Uncaught exceptions
- `rejections.log` - Unhandled rejections
Add `logs/` to your `.gitignore` if not already present.
If you use monitoring tools, add the new health endpoints:
**Kubernetes:**
```yaml
livenessProbe:
httpGet:
path: /alive
port: 8080
readinessProbe:
httpGet:
path: /ready
port: 8080
```
**Docker Compose:**
```yaml
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
```
All changes in v3.3.0 are backward compatible. Your existing code will continue to work without modifications.
Even without code changes, you automatically get:
✅ **Security**: Helmet.js protection, rate limiting, enhanced CORS
✅ **Logging**: Winston logger with file and console output
✅ **Error Handling**: Centralized error handling
✅ **Health Checks**: `/health`, `/ready`, `/alive` endpoints
✅ **Graceful Shutdown**: Proper cleanup on SIGTERM/SIGINT
✅ **Better Startup**: Enhanced startup banner with config info
✅ **Request Limits**: 10MB body size limit to prevent abuse
**Solution**: Run `npm install` to install new dependencies.
**Solution**: The logs directory is created automatically. Ensure write permissions.
**Solution**: Customize rate limits in your code:
```javascript
const { apiRateLimiter } = require('./server/middleware/security');
app.use('/api', apiRateLimiter);
```
**Solution**: This is normal if MongoDB is enabled but not connected. Check your MongoDB configuration.
If you need to rollback to v3.2.6:
```bash
npm install @misterzik/espressojs@3.2.6
```
- [GitHub Issues](https://github.com/misterzik/Espresso.js/issues)
- [Documentation](https://github.com/misterzik/Espresso.js)
- [Examples](./examples/)
1. Review the [CHANGELOG.md](./CHANGELOG.md) for detailed changes
2. Check out [examples/](./examples/) for code samples
3. Read the updated [README.md](./README.md) for full documentation
4. See [ENHANCEMENTS.md](./ENHANCEMENTS.md) for technical details
Happy upgrading! ☕