All 12 ModulesModule 1 of 12
Node.js + Express + TypeScript
Module 1: Network Inventory REST API
Build an enterprise-grade Network Inventory REST API using Node.js, Express, and TypeScript with layered architecture, DTO validation, and structured error handling.
Node.jsExpress.jsTypeScriptLayered ArchitectureDTO ValidationError MiddlewareJestSupertest
Level 1: Build
Level 1: Build — Production Layered REST API
Construct a resilient REST API to manage network routers, switches, and firewalls across DEV, QA, and PROD environments.
User Story:
As a Network Automation Engineer, I need a standard REST API to register, query, update, and decommission network devices with strict input validation.
Key Deliverables & Specifications:
- REST Endpoints: POST /api/devices, GET /api/devices, GET /api/devices/:id, PUT /api/devices/:id, DELETE /api/devices/:id
- Layered Directory Structure: Routes → Controllers → Services → Repositories → DTOs → Middlewares
- Strict TypeScript Interfaces for Device entities and Request payloads
- Centralized Global Error Middleware catching operational vs programmer errors
Implementation Roadmap:
1. **Initialize Project**: Configure TypeScript with strict mode (`noImplicitAny: true`, `strictNullChecks: true`).
2. **Define DTOs**: Create `CreateDeviceDto` and `UpdateDeviceDto` with validation constraints (valid IPv4/IPv6, non-empty hostnames).
3. **Build Layered Hierarchy**: Implement `DeviceRepository` (data layer), `DeviceService` (business rules), and `DeviceController` (HTTP translation).
4. **Implement Global Error Handling**: Create custom `AppError` class with HTTP status codes and operational flags.
5. **Add Logging**: Attach request correlation IDs (`x-request-id`) to every incoming request.