A RESTful API for managing books and borrowing records in a library system, built with Express.js, TypeScript, and MongoDB (Mongoose).
- 📘 Add, update, delete, and view books
- 🧾 Borrow books with due date tracking
- 🔄 Auto-updates book availability
- 📊 Get borrowing summaries using MongoDB aggregation
- ✅ Schema validation and unified error handling
- 📁 Scalable MVC architecture
- Node.js
- Express.js
- TypeScript
- MongoDB with Mongoose
- ts-node-dev for live development
- dotenv for environment variable management
src/
├── app.ts # Express app configuration
├── server.ts # Application entry point
├── config/ # MongoDB connection setup
├── interfaces/ # TypeScript type definitions
├── models/ # Mongoose models
├── controllers/ # Business logic
├── routes/ # Express routes
├── middlewares/ # Custom middleware (errors, etc.)
git clone https://github.com/ESRAILHAQUE/library-management-api.git
cd library-management-apinpm installCreate a .env in the root:
PORT=5000
MONGODB_URI=mongodb://localhost:27017/library-db- Development:
npm run dev- Production:
npm run start| Method | Endpoint | Description |
|---|---|---|
| POST | /api/books |
Add a new book |
| GET | /api/books |
List all books with filters & sorting |
| GET | /api/books/:id |
Get details of a specific book |
| PUT | /api/books/:id |
Update book details |
| DELETE | /api/books/:id |
Delete a book |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/borrow |
Borrow a book |
| GET | /api/borrow |
Get borrowing summaries |
GET /api/books?filter=FANTASY&sortBy=createdAt&sort=desc&limit=5"scripts": {
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
"build": "tsc",
"start": "npm run build && node dist/server.js"
}{
"message": "Validation failed",
"success": false,
"error": {
"name": "ValidationError",
"errors": {
"copies": {
"message": "Copies must be a positive number",
"kind": "min"
}
}
}
}- Name: Esrail Haque
- 🔗 GitHub: @ESRAILHAQUE