The backend service is a lightweight Node.js/Express API that reads CV data from MySQL and exposes it over HTTP. It runs on port 4000 inside its container and handles the full lifecycle of the database connection, including automatic retry on startup and reconnection if the link drops while the service is running.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/jperez77775/ProyectoDocker/llms.txt
Use this file to discover all available pages before exploring further.
Technology stack
| Component | Version |
|---|---|
| Node.js | 20 (Alpine) |
| Express | 4.18.x |
| mysql2 | 3.6.x |
| cors | 2.8.x |
docker-compose.yml.
API endpoint
The backend exposes a single endpoint:| Method | Path | Description |
|---|---|---|
GET | /cv | Returns the full CV object including persona data and education list |
Connection retry logic
Because Docker containers start in parallel and MySQL takes several seconds to become ready, the backend uses aconnectWithRetry() function that keeps attempting the connection until it succeeds. If the initial connection fails, it waits 5 seconds and tries again. Once connected, it also listens for runtime errors and reconnects automatically when it detects a dropped link.
server.js
isConnecting guard prevents duplicate connection attempts from stacking up. The error handler covers two specific codes:
PROTOCOL_CONNECTION_LOST— the TCP connection was closed unexpectedlyECONNREFUSED— the database container is not yet accepting connections
The backend service declares
depends_on: database: condition: service_healthy in docker-compose.yml. This means Docker waits for MySQL’s health check to pass before starting the backend container, reducing the number of retries needed in practice.UTF-8 encoding fix
MySQL can return strings as latin1-encoded bytes when the connection charset is misconfigured. ThesanearTexto() function works around this by re-reading each string through a binary buffer and decoding it as UTF-8, which correctly reconstructs accented characters like é and ó that would otherwise appear corrupted.
server.js
nombre, apellido, ciudad, titulo, and institucion — before the JSON is sent to the client.
Dockerfile
The backend image is built from a minimal Alpine-based Node 20 image. Dependencies are installed before copying the full source so that Docker can cache thenpm install layer and skip it on rebuilds that only change application code.
Dockerfile
Environment configuration
The database connection is configured with hardcoded values inserver.js:
| Parameter | Value |
|---|---|
host | database |
user | root |
password | rootpassword |
database | cv_db |
charset | utf8mb4 |
database resolves to the database container via the shared cv_network Docker bridge network defined in docker-compose.yml.