A simple Node.js backend server built with Express.js that provides enhanced error management and status monitoring capabilities. The system includes random error generation with detailed descriptions, IT section assignments, and persistent status tracking for testing error handling workflows.
- Health Check Endpoint: Returns current system status (200 OK or 500 Error)
- Random Error Simulation: Generates realistic error scenarios with detailed information
- IT Section Assignment: Automatically assigns errors to appropriate IT teams (DevOps, Developer)
- Persistent Status Storage: Maintains system state across server restarts
- Error Recovery: Built-in restart mechanism to clear error states
- Comprehensive Error Details: Includes severity levels, descriptions, and resolution steps
- JSON Responses: Structured API responses with timestamps and metadata
- Node.js (v14 or higher)
- npm (Node Package Manager)
-
Clone the repository:
git clone <repository-url> cd n8n-demo
-
Install dependencies:
npm install
Start the server:
npm start
# or
node server.jsThe server will start on http://localhost:3000 by default.
- URL:
GET /api/health - Status: 200 OK (if healthy) or 500 Error (if in error state)
- Description: Returns current system status with error details if applicable
Example Response (Healthy):
{
"status": "ok",
"message": "Server is running properly",
"lastUpdated": "2025-10-27T15:57:58.198Z",
"errorCount": 0,
"timestamp": "2025-10-27T16:01:09.531Z"
}Example Response (Error State):
{
"status": "fail",
"message": "Server is in error state",
"lastUpdated": "2025-10-27T16:01:07.030Z",
"errorCount": 2,
"timestamp": "2025-10-27T16:01:09.531Z",
"errorDetails": {
"id": "ssl_certificate",
"description": "SSL certificate expired - HTTPS connections failing due to expired certificate",
"severity": "high",
"itSection": "DevOps",
"resolution": "Renew SSL certificate and update server configuration"
}
}- URL:
GET /api/error - Status: 500 Internal Server Error
- Description: Randomly generates one of 5 predefined error scenarios and sets system status to fail
Example Response:
{
"status": "error",
"message": "Status set to fail - Server is now in error state",
"systemStatus": "fail",
"errorCount": 3,
"lastUpdated": "2025-10-27T16:01:07.030Z",
"timestamp": "2025-10-27T16:01:07.031Z",
"errorDetails": {
"id": "memory_leak",
"description": "Memory leak detected - Application memory usage exceeding 90% threshold",
"severity": "critical",
"itSection": "Developer",
"resolution": "Review application code for memory leaks and restart service",
"reportedAt": "2025-10-27T16:01:07.031Z"
}
}- URL:
POST /restart - Status: 200 OK
- Description: Resets system status to healthy and clears error state
Example Response:
{
"status": "success",
"message": "Status reset to ok - Server is now healthy",
"systemStatus": "ok",
"errorCount": 3,
"lastUpdated": "2025-10-27T16:01:16.840Z",
"timestamp": "2025-10-27T16:01:16.841Z",
"previousError": "Error cleared successfully"
}- URL:
GET / - Status: 200 OK
- Description: Returns comprehensive information about available endpoints and current system status
The system includes 5 predefined error scenarios that are randomly selected:
- Severity: High
- IT Section: DevOps
- Description: Database connection timeout - Unable to establish connection to primary database
- Resolution: Check database server status and network connectivity
- Severity: Critical
- IT Section: Developer
- Description: Memory leak detected - Application memory usage exceeding 90% threshold
- Resolution: Review application code for memory leaks and restart service
- Severity: Medium
- IT Section: DevOps
- Description: API rate limit exceeded - Too many requests from external service
- Resolution: Implement rate limiting and contact external service provider
- Severity: Critical
- IT Section: DevOps
- Description: Disk space critical - Available storage below 5% on production server
- Resolution: Clean up temporary files and expand storage capacity
- Severity: High
- IT Section: DevOps
- Description: SSL certificate expired - HTTPS connections failing due to expired certificate
- Resolution: Renew SSL certificate and update server configuration
Test the endpoints using curl:
# Test health endpoint (initial state)
curl http://localhost:3000/api/health
# Trigger random error
curl http://localhost:3000/api/error
# Check health with error details
curl http://localhost:3000/api/health
# Reset system to healthy state
curl -X POST http://localhost:3000/restart
# Test multiple error generations
for i in {1..3}; do
echo "=== Error Call $i ==="
curl -s http://localhost:3000/api/error | jq '.errorDetails | {id, description, severity, itSection}'
echo
done
# View all available error types
curl http://localhost:3000/ | jq '.availableErrors'n8n-demo/
βββ server.js # Main server file with enhanced error management
βββ package.json # Dependencies and scripts
βββ package-lock.json # Lock file for dependencies
βββ status.json # Persistent status storage (auto-generated)
βββ .gitignore # Git ignore file
βββ README.md # This file
The server runs on port 3000 by default. You can change this by setting the PORT environment variable:
PORT=8080 node server.jsThe system maintains persistent status in status.json:
{
"status": "fail",
"lastUpdated": "2025-10-27T16:01:19.569Z",
"errorCount": 5,
"lastError": {
"id": "api_rate_limit",
"description": "API rate limit exceeded - Too many requests from external service",
"severity": "medium",
"itSection": "DevOps",
"resolution": "Implement rate limiting and contact external service provider"
}
}- express: ^4.18.2 - Web framework for Node.js
This backend is perfect for:
- Testing Error Handling: Simulate various error scenarios for testing monitoring systems
- IT Team Training: Practice incident response with realistic error descriptions
- Workflow Testing: Test error detection and recovery processes
- Monitoring System Validation: Verify alert systems respond correctly to different error types
- Development Testing: Test application resilience to various failure modes
- Fork the repository
- Create a feature branch
- Make your changes
- Test your changes
- Submit a pull request
This project is licensed under the MIT License.
If you encounter any issues, please create an issue in the repository or contact the maintainer.