A Node.js server application that provides game-related APIs and services, built with Express.js, TypeScript, and Redis.
- Game search and details API
- Redis caching for improved performance
- Kubernetes deployment support
- Error logging and monitoring
- Security features with Helmet.js
- Rate limiting and request validation
- TypeScript support
- Docker containerization
- Node.js (v14 or higher)
- Redis server
- RAWG API key
- Docker (optional, for containerization)
- Kubernetes cluster (optional, for deployment)
- TypeScript
game-hub-server/
├── src/
│ ├── config/
│ │ ├── logger.ts
│ │ ├── redis.ts
│ │ └── routes.ts
│ ├── routes/
│ │ ├── gamesRoutes.ts
│ │ ├── genresRoutes.ts
│ │ ├── platformsRoutes.ts
│ │ ├── redisRoutes.ts
│ │ ├── healthRoutes.ts
│ │ └── index.ts
│ ├── services/
│ │ ├── rawgApiService.ts
│ ├── middlewares/
│ │ ├── common.ts
│ │ ├── compression.ts
│ │ ├── index.ts
│ │ ├── performance.ts
│ │ ├── sanitization.ts
│ │ ├── security.ts
│ ├── types/
│ │ └── index.ts
│ └── server.ts
├── k8s/
│ ├── app.yaml
│ └── secret.yaml
├── dist/ # Compiled JavaScript files
├── logs/ # Error logs
├── docker-compose.yml
├── Dockerfile
├── .dockerignore
├── .env.example
├── .eslintrc.json
├── tsconfig.json
├── package.json
└── README.md
-
Clone the repository:
git clone https://github.com/niteshpk/game-hub-server cd game-hub-server
-
Install dependencies:
npm install
-
Set up environment variables: Copy
.env.example
to.env
and update the values:cp .env.example .env
Required environment variables:
PORT=3000 REDIS_HOST=localhost REDIS_PORT=6379 REDIS_USERNAME=default REDIS_PASSWORD=your_redis_password RAWG_API_KEY=your_rawg_api_key
-
Start Redis server:
# Using Docker Compose (recommended) docker-compose up -d redis # Or using Docker directly docker run --name game-hub-redis -p 6379:6379 -d redis # Or start your local Redis server redis-server
-
Build the TypeScript code:
npm run build
-
Start the application:
# Production npm start # Development with hot-reload npm run dev
-
Build the Docker image:
docker build -t game-hub-server .
-
Run the container:
docker run -p 3000:3000 --env-file .env game-hub-server
-
Or use Docker Compose:
docker-compose up -d
-
Create the secret:
kubectl apply -f k8s/secret.yaml
-
Deploy the application:
kubectl apply -f k8s/app.yaml
-
Verify the deployment:
kubectl get pods kubectl get services
GET /api/v1/games/search?query=<search_term>
: Search for gamesGET /api/v1/games/:id
: Get detailed information about a specific gameGET /api/v1/genres
: Get all genresGET /api/v1/:slug/movies
: Get all movies for a specific gameGET /api/v1/:slug/screenshots
: Get all screenshots for a specific gameGET /api/v1/platforms
: Get all platformsGET /api/v1/health
: Get health status
- Build TypeScript:
npm run build
- Run for production:
npm run start
- Run for development:
npm run dev
- Lint code:
npm run lint
Variable | Description | Required |
---|---|---|
PORT | Server port | Yes |
REDIS_HOST | Redis host | Yes |
REDIS_PORT | Redis port | Yes |
REDIS_USERNAME | Redis username | Yes |
REDIS_PASSWORD | Redis password | Yes |
RAWG_API_KEY | RAWG API key | Yes |
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.