Node.js + Express + TypeScript
MongoDB + Mongoose
Redis Caching (Windows Supported)
Joi Validation
Centralized Error Handling
Service Layer Architecture
✔ Redis caching logic
✔ Cache invalidation patterns
✔ Clean folder structure (MVC + Service)
✔ Real-world CRUD API design
git clone https://github.com/your-username/article-api.git
cd article-api
npm install
Create a .env file:
PORT=3000
MONGO_URI=mongodb://127.0.0.1:27017/article-api
REDIS_URL=redis://127.0.0.1:6379
Download MongoDB Community Server:
👉 https://www.mongodb.com/try/download/community
Start MongoDB service (Windows):
net start MongoDB
Download Redis for Windows:
👉 https://github.com/tporadowski/redis/releases
Check Redis is running:
redis-cli ping
Expected output:
PONG
Start Redis manually:
redis-server
Or start Redis Windows service:
net start redis
npm run dev
npm run build
npm start
📡 API Endpoints
Base URL http://localhost:3000/api/articles
GET /api/articles
Redis cache TTL: 30 seconds
GET /api/articles/:id
TTL: 60 seconds
Cache invalidates on update/delete
POST /api/articles
Body: {
"title": "Redis Caching in Node.js",
"content": "Redis helps speed up applications by caching frequently accessed data."
}
PUT /api/articles/:id
DELETE /api/articles/:id
Cache invalidation happens automatically.
✔ Cache GET all articles
✔ Cache GET article by ID
✔ Automatic cache invalidation on POST/PUT/DELETE
✔ Custom TTL support
✔ Redis helper utilities
{
"title": "Understanding JavaScript Closures",
"content": "A closure gives access to outer scope variables from an inner function."
}
Node.js + Express = Backend framework
TypeScript = Type safety
MongoDB = Database
Mongoose = ODM
Redis = Caching
Joi = Request validation
MVC + Services = Clean architecture
🐞 Error Handling Included
Global error handler
Joi validation errors
MongoDB validation errors
Async wrapper (catchAsync)
redis-cli keys *
redis-cli del articles:all
redis-cli flushall
Feel free to fork the project and submit PRs.