A comprehensive REST API providing detailed information about countries worldwide, built with Express.js and featuring a beautiful Dracula-themed frontend.
- β
REST API with versioning (
/api/v1) - π Security with Helmet middleware
- β° Rate limiting (1000 requests/hour)
- π CORS enabled for all origins
- π Swagger documentation
- π¨ EJS frontend with Dracula theme
- π³ Docker support with health checks
- π 249 countries with comprehensive data
# Build and run with Docker
docker build -t countries-api .
docker run -p 3000:3000 countries-api
# Or use Docker Compose
docker-compose up -d# Install dependencies
npm install
# Start the server
npm start| Method | Endpoint | Description |
|---|---|---|
| GET | /countries |
Get all countries |
| GET | /countries/:code |
Get country by ISO code |
| GET | /countries/search/:name |
Search countries by name |
- Swagger UI: http://localhost:3000/docs
- Swagger JSON: http://localhost:3000/api/docs
- Frontend: http://localhost:3000/
# Get all countries
curl http://localhost:3000/api/v1/countries
# Get specific country (USA)
curl http://localhost:3000/api/v1/countries/US
# Search for countries containing "United"
curl http://localhost:3000/api/v1/countries/search/United{
"timezones": ["America/New_York", "America/Chicago", "..."],
"latlng": [38, -97],
"name": "United States",
"country_code": "US",
"capital": "Washington D.C."
}- Helmet: Security headers protection
- Rate Limiting: 1000 requests per hour per IP
- CORS: Cross-origin resource sharing enabled
- Health Checks: Built-in health monitoring
- Non-root User: Docker container runs as non-root user
countries/
βββ server.js # Main application file
βββ countries.json # Countries data
βββ healthcheck.js # Health check script
βββ package.json # Dependencies
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose setup
βββ .dockerignore # Docker ignore file
βββ public/ # Static assets
β βββ css/style.css # Dracula theme styles
β βββ js/main.js # Frontend JavaScript
βββ views/ # EJS templates
βββ index.ejs # Homepage
βββ country.ejs # Country detail page
βββ 404.ejs # 404 error page
βββ error.ejs # Error page
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Server port |
NODE_ENV |
production |
Environment mode |
# Build image
docker build -t countries-api .
# Run container
docker run -d --name countries-api -p 3000:3000 countries-api
# Check health
docker exec countries-api node healthcheck.js
# View logs
docker logs countries-api
# Stop and remove
docker stop countries-api && docker rm countries-api# Start services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Rebuild and restart
docker-compose up -d --buildFor development with hot reload:
# Start development version
docker-compose --profile dev up -d
# This will run on port 3001 with volume mountingThe application includes built-in health checks:
- Health endpoint: Internal health check script
- Docker health check: Automatic container health monitoring
- API status: Monitors API endpoint availability
-
Port already in use
# Find process using port 3000 lsof -i :3000 # Kill process kill -9 <PID>
-
Docker build issues
# Clean Docker cache docker system prune -a # Rebuild without cache docker build --no-cache -t countries-api .
-
Rate limiting
- Default limit: 1000 requests/hour
- Wait for limit reset or modify in
server.js
- Use Docker for consistent environments
- Enable Docker health checks for monitoring
- Consider adding Redis for caching in production
- Monitor API response times with built-in logging
- Fork the repository
- Create a feature branch
- Make changes
- Test with Docker
- Submit a pull request
ISC License - see package.json for details
- Backend: Node.js, Express.js
- Frontend: EJS, Custom CSS (Dracula theme)
- Security: Helmet, Rate limiting, CORS
- Documentation: Swagger/OpenAPI
- Containerization: Docker, Docker Compose
- Data: JSON file with 249 countries
π Ready to explore the world's countries? Start the server and visit http://localhost:3000!