Skip to content

ESRAILHAQUE/library-management-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Library Management API

Node.js TypeScript MongoDB Express

A RESTful API for managing books and borrowing records in a library system, built with Express.js, TypeScript, and MongoDB (Mongoose).


🚀 Features

  • 📘 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

🛠️ Tech Stack

  • Node.js
  • Express.js
  • TypeScript
  • MongoDB with Mongoose
  • ts-node-dev for live development
  • dotenv for environment variable management

📁 Project Structure

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.)

⚙️ Getting Started

1️⃣ Clone the repo

git clone https://github.com/ESRAILHAQUE/library-management-api.git
cd library-management-api

2️⃣ Install dependencies

npm install

3️⃣ Configure .env file

Create a .env in the root:

PORT=5000
MONGODB_URI=mongodb://localhost:27017/library-db

4️⃣ Run the server

  • Development:
npm run dev
  • Production:
npm run start

📘 API Endpoints

📚 Book Endpoints

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

📖 Borrow Endpoints

Method Endpoint Description
POST /api/borrow Borrow a book
GET /api/borrow Get borrowing summaries

🔎 Example Query

GET /api/books?filter=FANTASY&sortBy=createdAt&sort=desc&limit=5

📦 Scripts

"scripts": {
  "dev": "ts-node-dev --respawn --transpile-only src/server.ts",
  "build": "tsc",
  "start": "npm run build && node dist/server.js"
}

🔐 Error Response Format

{
  "message": "Validation failed",
  "success": false,
  "error": {
    "name": "ValidationError",
    "errors": {
      "copies": {
        "message": "Copies must be a positive number",
        "kind": "min"
      }
    }
  }
}

Live Link


👨‍💻 Author

About

A RESTful Library Management API using Express, TypeScript, and MongoDB.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published