This is a Node.js backend application built with Express, MongoDB, and Redis. It provides RESTful APIs to manage FAQs and Grades. The project features rate limiting, caching with Redis, request validation using Joi, and an error handling middleware.
- FAQ Management: Create, read, update, and delete FAQs.
- Grades Management: Manage student grades, including profile images, classes, subjects, and marks.
- Caching: Redis-backed caching for read-heavy operations.
- Rate Limiting: Protects endpoints from abuse using rate limits backed by Redis.
- Validation: Request body validation using Joi.
- Docker Support: Fully containerized with Docker and Docker Compose.
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB (with Mongoose)
- Cache/Rate Limiting: Redis
- Validation: Joi
- Security: bcrypt, jsonwebtoken, express-rate-limit
- Node.js (v16+ recommended)
- MongoDB (running locally or a cloud instance like Atlas)
- Redis (running locally or a cloud instance)
- Docker (optional, for containerized environment)
Create a .env file in the root directory based on the following pattern:
PORT=3000
MONGO_URI=mongodb://localhost:27017/faq-data
JWT_SECRET=your_jwt_secret_here
REDIS_URL=redis://localhost:6379 # Use redis://redis:6379 if running via Docker
REDIS_PASSWORD=your_redis_password_here-
Clone the repository:
git clone <repository_url> cd faq-grading-backend-nodejs
-
Install dependencies:
npm install
-
Start the server (Development mode):
npm start
The server uses
nodemonfor auto-reloading and will typically run onhttp://localhost:3000orhttp://localhost:3008if the PORT environment variable is missing.
You can easily spin up the API, MongoDB, and Redis using Docker Compose.
- Make sure Docker and Docker Compose are installed.
- Run the following command in the root of your project:
The API will be available on
docker-compose up --build
http://localhost:5000(mapped securely from the container).
- GET
/api/faqs- Get a list of FAQs - POST
/api/faqs- Create a new FAQ - PUT
/api/faqs/:id- Update an existing FAQ by ID - DELETE
/api/faqs/:id- Delete an FAQ by ID
All grade routes are protected primarily by rate limiting. GET routes are cached to optimize performance.
- GET
/api/grades/all- Get all grades - GET
/api/grades/- Get grades with optional query parameters (e.g.,?name=qw) - GET
/api/grades/:id- Get a single grade by ID - POST
/api/grades/- Create a new grade(Requires validation) - PUT
/api/grades/:id- Update an existing grade by ID(Requires validation) - DELETE
/api/grades/:id- Delete a grade by ID