expressed-example-app
v2.1.1
Published
Advanced Express.js application featuring high-performance routing with custom hooks, declarative route definitions, and integrated queue system for background task processing. Perfect for scalable web applications requiring sophisticated routing and asyn
Maintainers
Readme
Express-Router-BDS Example Application
This is a sample Express.js application demonstrating the usage of the express-router-bds routing system with custom hooks, advanced features, and integrated queue system.
Overview
This example application showcases:
- High-performance routing with
express-router-bds - JSON-based route configuration
- Custom hook system implementation
- Parameterized route handling
- Directory-based route loading
- Integrated queue system with
express-queued - Declarative route definitions in separate JSON files
Features
- Modular Route Configuration: Routes defined in JSON files for easy maintenance
- Custom Hooks: Comprehensive hook system with
pre_route_load,post_route_load,before_route_handler,after_route_handler,route_handler_error, and more - Parameterized Routes: Support for dynamic routes like
/users/:idand/products/:category/:id - Integrated Queue System: Background task processing with
express-queued - Declarative Routes: Separate route files for different functionalities
- Extensible Architecture: Easy to extend with custom middleware and hooks
Project Structure
express-app/
├── app.js # Main application entry point
├── queue-system.js # Queue system integration
├── hooks-config.js # Base hook configurations
├── hooks-personalizados.js # Custom hook implementations
├── controllers/
│ ├── mainController.js # Home, init and queue route handlers
│ ├── productController.js # Product route handlers
│ └── userController.js # User route handlers
├── routes/
│ ├── main-routes.json # Main route definitions in JSON format
│ └── queue-routes.json # Queue-related route definitions
└── node_modules/
├── express-router-bds/ # Custom routing system
└── express-queued/ # Queue systemAvailable Endpoints
Main Endpoints
GET /- Home page with welcome messageGET /init- Initialization endpointGET /users/:id- Get user by IDGET /products/:category/:id- Get product by category and IDGET /test-hook- Test endpoint for hook demonstration
Queue System Endpoints
GET /queue-status- Get the status of the queue systemGET /start-queues- Start the queue systemGET /stop-queues- Stop the queue systemPOST /process-user- Add a user processing task to the queuePOST /process-product- Add a product processing task to the queuePOST /send-email- Add an email sending task to the queue
Queue System
The application integrates express-queued for background task processing:
- Multiple Queues: Dedicated queues for different types of tasks
- Configurable Concurrency: Control how many tasks execute simultaneously per queue
- Retry System: Automatic failure handling with configurable retries
- Priority Management: Assign priorities to tasks
- Hooks Integration: Customize processing with hooks
Queue Types
procesamiento-general- General processing tasksenvio-correos- Email sending tasksprocesamiento-usuarios- User processing tasksprocesamiento-productos- Product processing tasks
Hook System
The application demonstrates several types of hooks:
pre_route_load- Executes before loading routes from a filepost_route_load- Executes after loading routes from a filebefore_route_processing- Executes before processing any routeroute_matched- Executes when a matching route is foundbefore_route_handler- Executes before executing a route handlerafter_route_handler- Executes after executing a route handlerroute_handler_error- Executes when a route handler error occurs
Installation
npm installUsage
Start the server:
npm startThe application will be available at http://localhost:3000
Testing
Test the main endpoints:
curl http://localhost:3000
curl http://localhost:3000/users/123
curl http://localhost:3000/products/electronics/456Test the queue system:
# Check queue status
curl http://localhost:3000/queue-status
# Add a user processing task
curl -X POST http://localhost:3000/process-user \
-H "Content-Type: application/json" \
-d '{"userId": "123", "name": "John Doe", "email": "[email protected]"}'
# Add an email sending task
curl -X POST http://localhost:3000/send-email \
-H "Content-Type: application/json" \
-d '{"to": "[email protected]", "subject": "Test", "content": "Test content"}'License
This project is part of the express-router-bds ecosystem and follows the same licensing terms.
