0% found this document useful (0 votes)
8 views2 pages

NodeJS Practical Task For Exp.

Uploaded by

flamiedess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

NodeJS Practical Task For Exp.

Uploaded by

flamiedess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Task: "Library Management System with Real-Time Updates"

Objective:

Build a REST API for a simple library management system while incorporating Socket.IO to
notify clients in real time about book availability and borrowing activities.

API Endpoints

1. Books
○ GET /books: Fetch a list of all books with optional filters (e.g., author, genre).
○ POST /books: Add a new book (title, author, genre, stock count).
2. Borrowing
○ POST /borrow: Borrow a book. Decrease the stock count.
○ POST /return: Return a book. Increase the stock count and update borrowing
history.
○ GET /borrow-history: Fetch borrowing history with data such as user
name,bookname, taken_at, return_at with filters (e.g., user name, book
name) and pagination
3. Login API
○ POST /login : will return the JWT token which will be used by above API
4. Authentication
○ Use JWT for authentication and role-based access (e.g., only admins can
add/delete books).
○ For now in user table you can create manually two user one is admin and one
user

Socket.IO Integration

Add real-time features using Socket.IO:

1. Real-Time Notifications
○ Notify all connected clients whenever:
■ A book is borrowed.
■ A book is returned.
○ Emit events like bookBorrowed and bookReturned.
2. Example:

Client listens for bookBorrowed:


javascript
socket.on("bookBorrowed", (data) => {
console.log("Book borrowed:", data);
});
3. Live Stock Updates
○ Notify clients when the stock count for any book changes.
○ Emit an event like stockUpdated with the book details and new stock count.

AWS Integration

1. File Upload
○ Use AWS S3 for uploading book cover images.
○ Add an endpoint POST /upload-book-cover to handle uploads and save
the S3 URL.

Database

Use any SQL database to store:

● Books: Schema for title, author, genre, stock count, and optional cover image.
● Borrow History: Schema to track borrowing and returning activities.

Additional Features

1. Validation
○ Validate input data (e.g., stock count must be a positive number).
2. Error Handling
○ Return meaningful error messages (e.g., trying to borrow a book that's out of
stock).

You might also like