Proof of Concept for a RESTful API made with Node.js LTS/Jod (v22) and Express.js 5 in TypeScript. Manage football player data with SQLite, Sequelize ORM, Swagger documentation, and in-memory caching.
- Features
- Tech Stack
- Prerequisites
- Quick Start
- API Documentation
- API Endpoints
- Testing
- Docker
- Environment Variables
- Project Structure
- Available Scripts
- Contributing
- License
- β RESTful CRUD operations for football player data
- π Interactive API documentation with Swagger UI
- β‘ In-memory caching with node-cache (1-hour TTL)
- π₯ Health check endpoint for monitoring
- π³ Full Docker containerization with Docker Compose
- ποΈ SQLite database with Sequelize ORM
- π Security headers with Helmet
- π§ͺ Comprehensive integration tests with Jest and Supertest
- π¨ TypeScript strict mode enabled
- π Hot reload with nodemon for development
- Runtime: Node.js 22 (LTS/Jod)
- Framework: Express.js 5
- Language: TypeScript 5.9
- Database: SQLite3 with Sequelize ORM
- Testing: Jest 30 with Supertest
- Documentation: Swagger (OpenAPI 3.0)
- Caching: node-cache
- Security: Helmet, CORS
- Containerization: Docker with multi-stage builds
- Code Quality: ESLint, Prettier, Commitlint
Before you begin, ensure you have the following installed:
- Node.js 22 (LTS/Jod) or higher
- npm (comes with Node.js)
- Docker and Docker Compose (optional, for containerized setup)
git clone https://github.com/nanotaboada/ts-node-samples-express-restful.git
cd ts-node-samples-express-restfulnpm installnpm run devThe server will start on http://localhost:9000 with the following output:
> ts-node-samples-express-restful@1.0.0 dev
> nodemon
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): src/**/*
[nodemon] watching extensions: ts
[nodemon] starting `ts-node ./src/server.ts`
π Running at http://localhost:9000- API:
http://localhost:9000 - Swagger Documentation:
http://localhost:9000/swagger/ - Health Check:
http://localhost:9000/health
Interactive API documentation is available via Swagger UI at:
http://localhost:9000/swagger/
You can also access the OpenAPI JSON specification at http://localhost:9000/swagger.json.
| Method | Endpoint | Description |
|---|---|---|
| GET | /players |
Retrieve all players |
| GET | /players/:id |
Retrieve player by ID |
| GET | /players/squadNumber/:squadNumber |
Retrieve player by squad number |
| POST | /players |
Create a new player |
| PUT | /players/:id |
Update an existing player |
| DELETE | /players/:id |
Delete a player |
| GET | /health |
Health check endpoint |
Run the test suite with Jest:
# Run all tests
npm test
# Run tests with coverage report
npm run coverage
# Run linter
npm run lint
# Validate commit message format
npm run lint:commitTests are located in the tests/ directory and use Supertest for integration testing. Coverage reports are generated for controllers, services, and routes only.
This project includes full Docker support with multi-stage builds and Docker Compose for easy deployment.
npm run docker:build
# or
docker compose buildnpm run docker:up
# or
docker compose upNote: On first run, the container copies a pre-seeded SQLite database into a persistent volume. On subsequent runs, that volume is reused and the data is preserved.
npm run docker:down
# or
docker compose downTo remove the volume and reinitialize the database from the built-in seed file:
docker compose down -vThe containerized application runs on port 9000 and includes health checks that monitor the /health endpoint every 30 seconds.
Create a .env file in the root directory to customize configuration:
# Server port (default: 9000)
PORT=9000
# Database storage path (default: storage/players-sqlite3.db)
# In Docker: /storage/players-sqlite3.db
STORAGE_PATH=storage/players-sqlite3.dbsrc/
βββ app.ts # Express app setup & middleware configuration
βββ server.ts # HTTP server initialization & lifecycle
βββ controllers/ # Request handlers with Swagger annotations
βββ services/ # Business logic + caching layer
βββ database/ # Sequelize DB access (interfaces + implementations)
βββ models/ # Sequelize models (Player)
βββ routes/ # Express Router definitions
βββ docs/ # Swagger configuration & doc generation
βββ middlewares/ # Custom middleware (swagger CSP)
tests/ # Integration tests with supertest
scripts/ # Docker entrypoint & healthcheck scripts
storage/ # Pre-seeded SQLite database
Architecture: Layered architecture (Route β Controller β Service β Database) with dependency injection via constructors and interface-based contracts.
Figure: Simplified, conceptual project structure and main application flow. Not all dependencies are shown.
| Script | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm start |
Run compiled application from dist/ |
npm run build |
Compile TypeScript to JavaScript |
npm test |
Run Jest tests with --detectOpenHandles flag |
npm run coverage |
Generate test coverage report |
npm run lint |
Run ESLint on all files |
npm run lint:commit |
Validate last commit message format |
npm run swagger:docs |
Generate swagger.json from JSDoc annotations |
npm run docker:build |
Build Docker image |
npm run docker:up |
Start Docker container |
npm run docker:down |
Stop and remove Docker volume |
Contributions are welcome! Please read CONTRIBUTING.md for details on the code of conduct and the process for submitting pull requests.
Key guidelines:
- Follow Conventional Commits for commit messages
- Ensure all tests pass (
npm test) - Run linter before committing (
npm run lint) - Keep changes small and focused
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments: This solution has been developed using Visual Studio Code.
All trademarks, registered trademarks, service marks, product names, company names, or logos mentioned are the property of their respective owners and are used for identification purposes only.
