This is a Node.js-based library management system using Express and Mongoose. It provides an API to manage users, books, and transactions (issuing and returning books).
- Manage users and books.
- Issue and return books.
- Search for books and retrieve information about transactions.
- Node.js
- MongoDB
-
Clone the repository:
git clone https://github.com/aditya-singh-99/Library-Management-API.git cd Library-Management-API npm install -
Install the dependencies:
npm install
-
Set up environment variables:
Copy the .env.sample file to create a .env file and update the necessary values:
cp .env.sample .env
Edit the .env file to add your MongoDB URIs:
PORT=Your_Port MONGO_LIBRARY_URI=Library_DB_Connection_String MONGO_TRANSACTIONS_URI=Transactions_DB_Connection_String
-
Start the server:
npm install
Sure! Here are your API endpoints in Markdown format:
- Get All Users
- Endpoint:
GET /users/all - Description: Retrieve all users.
- Endpoint:
-
Get All Books
- Endpoint:
GET /books/all - Description: Retrieve all books in the library.
- Endpoint:
-
Search Books
- Endpoint:
GET /books/search - Description: Search books by name, category, or rent range.
- Query Params:
name(optional) - Search by book namecategory(optional) - Search by book categoryrent_min(optional) - Minimum rent valuerent_max(optional) - Maximum rent value
- Endpoint:
-
Issue Book
- Endpoint:
POST /transactions/issue - Description: Issue a book to a user.
- Request Body:
name- User nameemail- User emailphone- User phonetitle- Book title
- Endpoint:
-
Return Book
- Endpoint:
POST /transactions/return - Description: Return a book issued to a user.
- Request Body:
name- User nameemail- User emailphone- User phonetitle- Book title
- Endpoint:
-
Get Issued Books
- Endpoint:
GET /transactions/issued - Description: Retrieve books currently issued.
- Query Params:
title(required) - Book title
- Endpoint:
-
Get Total Rent by Book
- Endpoint:
GET /transactions/book - Description: Retrieve the total rent generated by a specific book.
- Query Params:
title(required) - Book title
- Endpoint:
-
Get Transactions by User
- Endpoint:
GET /transactions/user - Description: Retrieve all transactions related to a specific user.
- Query Params:
email(required) - User email
- Endpoint:
-
Get Transactions in Date Range
- Endpoint:
GET /transactions/range - Description: Retrieve all transactions issued within a specific date range.
- Query Params:
startDate(required) - Start date inMM-DD-YYYYformatendDate(required) - End date inMM-DD-YYYYformat
- Endpoint:
All endpoints return appropriate HTTP status codes and error messages if an error occurs (e.g., 404 Not Found if a resource is not found).
- Node.js: Backend runtime.
- Express: Web framework for Node.js.
- Mongoose: MongoDB object modeling for Node.js.