KodeKamper is an extensive REST API service provide for consumer to build their own frontend platform on demand.
The API is live at kodekamper.app
Test Automation with Postman:
Test documentation with Postman here Or click here "Run In Postman".
- Version: 1.0.0
- License: MIT
- Author: Rodney's profile
- HTTP Essentials
- Postman Client
- RESTful APIs
- Express Framework
- Routing & Controller Methods
- MongoDB Atlas & Compass
- Mongoose ODM
- Advanced Query (Pagination, filter, etc)
- Models & Relationships
- Middleware (Express & Mongoose)
- MongoDB Geospatial Index / GeoJSON
- Geocoding
- Custom Error Handling
- User Roles & Permissions
- Aggregation
- Photo Upload
- Authentication With JWT & Cookies
- Emailing Password Reset Tokens
- Custom Database Seeder Using JSON Files
- Password & Token Hashing
- Security: NoSQL Injection, XSS, etc
- Creating Documentation
- Deployment With PM2, NGINX, SSL
Copy .env.example to .env and update values.
Alternatively, set environment variables in your shell or GitHub Environment secrets (available to workflows as env vars).
Runtime DB/Cache envs (built automatically if URLs are not provided):
MONGODB_HOST,MONGODB_DB,MONGODB_USERNAME,MONGODB_PASSWORDREDIS_HOST,REDIS_PORT,REDIS_USERNAME,REDIS_PASSWORD
Optional full URLs (override the above):
MONGODB_URI,REDIS_URL
Monitoring/SSL vars:
DOMAIN,CERTBOT_EMAIL,ALERT_WEBHOOK_URL,CHECK_URLS,TCP_CHECKS
Kamal CI/CD secrets examples:
- .kamal/secrets.production.example
- .kamal/secrets.staging.example
Example monitor env: see docker/monitor/monitor.env.example
npm installNote: This project uses npm. Node version is managed via .nvmrc (v20.11.1).
# Run in dev mode
npm run dev
# Run in prod mode
npm startThe API includes a comprehensive health endpoint:
- Endpoint:
GET /api/v1/health - Returns: MongoDB connection status, Redis connection status, and uptime
- Use case: Docker health checks, load balancer monitoring, uptime tools
{
"success": true,
"data": {
"status": "ok",
"mongo": "connected",
"redis": "connected",
"uptimeSeconds": 1234.56
}
}Automatic response caching is enabled for:
GET /api/v1/bootcamps(60s TTL)GET /api/v1/health(10s TTL)
Caching activates automatically when Redis is available. The API supports both:
- Full connection URL:
REDIS_URL - Component-based:
REDIS_HOST,REDIS_PORT,REDIS_USERNAME,REDIS_PASSWORD
See middleware/cache.js for implementation.
The API implements multiple security layers:
- Double-submit cookie pattern using
csrf-csrf - Automatic protection for POST/PUT/PATCH/DELETE requests
- Secure, httpOnly cookies
- Password reset URLs use trusted
APP_BASE_URL - Prevents host header injection attacks
- Global: 100 requests per 10 minutes
- Auth routes: 20 requests per 15 minutes (login, register, password reset)
- Blocks common scanner user-agents (Nikto, sqlmap, etc.)
- Blocks suspicious paths (wp-admin, phpmyadmin, .env, etc.)
- Helmet: Secure HTTP headers
- XSS-clean: Cross-site scripting protection
- express-mongo-sanitize: NoSQL injection prevention
- HPP: HTTP parameter pollution protection
- CORS: Cross-origin resource sharing
- Request size limit: 10kb max body size
For complete security documentation, see SECURITY.md
See middleware:
middleware/rateLimiters.jsmiddleware/botBlocker.jsmiddleware/error.js
Seed the database with users, bootcamps, courses and reviews from the _data/ folder:
# Destroy all data
npm run data:destroy
# Import all data
npm run data:importNote: Seeder data is for development only. Tests create their own isolated test data.
Start API + MongoDB + Redis locally:
docker compose up -dThe stack includes:
- API: Multi-stage Dockerfile with dev target, hot reload via nodemon
- MongoDB 6: Persistent data in
mongo_datavolume - Redis 7: Persistent data in
redis_datavolume - Port: 5001 (to avoid macOS AirPlay conflict on 5000)
The app auto-builds database URIs from components (see config/db.js and utils/redisClient.js):
MongoDB:
MONGODB_HOST,MONGODB_DB,MONGODB_USERNAME,MONGODB_PASSWORD- Or override with:
MONGODB_URI
Redis:
REDIS_HOST,REDIS_PORT,REDIS_USERNAME,REDIS_PASSWORD- Or override with:
REDIS_URL
The Dockerfile includes optimized targets:
- dev: Development with nodemon, all dependencies
- staging: PM2 cluster mode, production dependencies
- prod: PM2 cluster mode, optimized for production
Stop:
docker compose downKamal 2.0 handles zero-downtime deployments with kamal-proxy for SSL/routing (no Nginx required).
- main - Main development branch
- staging - Auto-deploys to staging.kodekamper.app when updated
- production - Manual deployment to kodekamper.app only
Staging (Automatic):
- Push to
stagingbranch (or mergemain→staging) - QA workflow runs (lint, test, audit)
- If QA passes → Auto-deploy to staging.kodekamper.app
Production (Manual):
- Go to GitHub Actions → Deploy (Staging/Production) → Run workflow
- Select "production" environment
- Manual approval required
Kamal configs:
config/deploy.yml(production)config/deploy.staging.yml(staging)
Secrets:
.kamal/secrets.production(use examples as templates).kamal/secrets.staging
Production (/srv/www/production/kodekamper/):
- MongoDB: localhost:27017
- Redis: localhost:6379
- SSL: kodekamper.app (kamal-proxy)
Staging (/srv/www/staging/kodekamper/):
- MongoDB: localhost:27018
- Redis: localhost:6380
- SSL: staging.kodekamper.app (kamal-proxy)
Accessories (MongoDB/Redis) are managed by Kamal as Docker containers.
The project includes 6 test suites with 100+ test cases:
# Run tests locally
npm test
# Run with coverage
npm run test:ciTest Coverage:
tests/auth.test.js- Authentication & authorization (register, login, JWT)tests/bootcamps.test.js- Bootcamp CRUD, pagination, filtering, geolocationtests/courses.test.js- Course management, relationshipstests/reviews.test.js- Review system, ratings, ownershiptests/users.test.js- Admin user managementtests/health.test.js- Health endpoint monitoring
Test Infrastructure:
- Uses mongodb-memory-server for local testing (no MongoDB required)
- GitHub Actions uses real MongoDB/Redis service containers
- Mock geocoder to avoid external API calls
- Automatic database cleanup between tests
- 30-second timeout for integration tests
Automated checks run on every PR and push to staging:
- ✅ ESLint: Code linting with security plugin
- ✅ Prettier: Code formatting validation
- ✅ Jest: Full test suite with coverage reports
- ✅ npm audit: Dependency vulnerability scanning
- ✅ Codecov: Coverage tracking and reporting
- ✅ CodeQL: Static analysis security testing (SAST)
- ✅ Gitleaks: Secret scanning (API keys, tokens, passwords)
Husky runs Gitleaks before every commit:
# Install Gitleaks (macOS)
brew install gitleaks
# Hook runs automatically on git commit
gitleaks protect --redact --staged --config .gitleaks.tomlDeployment is gated on all QA checks passing.
To package.json add "type": "module"
{
"name": "esm-modules",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": ["REST API", "API", "Postman", "CRUD", "Node"],
"author": "Rodney Hammad",
"license": "MIT",
"dependencies": {
"express": "^4.17.1"
},
"type": "module"
}