The Book Library Application allows users to manage their personal library by adding books, marking them as read or unread, viewing book details, and filtering books based on their status. This application is built using Node.js, ExpressJS, and JSON as a data store.
-
Book Management:
- Add new books with properties such as title, author, status, description, and date.
- View the list of all books or individual book details.
- Update a book's read/unread status.
- Delete books.
-
Filtering:
- Filter books to display only read or unread books.
-
Search Functionality: (Bonus)
- Search books by title or author.
-
Error Handling:
- Displays appropriate error messages for invalid requests or actions.
-
Clone the Repository
git clone https://github.com/aabisht/nodebooklib.git cd nodebooklib
-
Install Dependencies
npm install
-
Run the Application
npm run dev
-
Access the Application
- Open your browser and navigate to
http://localhost:3000
.
- Open your browser and navigate to
- URL:
/api/add
- Method:
POST
- Request Body:
{ "title": "Book Title", "author": "Book Author", "status": true, "description": "Description of the book", "date": "2020-10-31 05:42:49" }
- Response:
{ "success": true, "message": "Book added successfully", "id": <book-id> }
- URL:
/api/list
- Method:
GET
- Query Parameters:
status
(optional):read
orunread
.page
(optional): Page number for pagination.
- Response:
{ "page": 1, "pageSize": 10, "totalPages": 6, "totalItems": 51, "items": [ { "id": <book-id>, "title": "Book Title", "author": "Book Author", "status": true, "description": "Description of the book", "date": "2020-10-31 05:42:49" } {...} ] }
- URL:
/api/book
- Method:
GET
- Query Parameters:
id
: Unique ID of the book.
- Response:
{ "id": "<book-id>, "title": "Book Title", "author": "Book Author", "status": true, "description": "Description of the book", "date": "2020-10-31 05:42:49" }
- URL:
/api/update
- Method:
PUT
- Request Body:
{ "id": <book-id>, "title": "Book Title", "author": "Book Author", "status": false, "description": "Description of the book", "date": "2020-10-31 05:42:49" }
- Response:
{ "success": true, "message": "Book with ID <book-id> updated successfully.", "id": <book-id> }
- URL:
/api/delete
- Method:
DELETE
- Request Body:
{ "id": <book-id> }
- Response:
{ "success": true, "message": "Book with ID <book-id> removed successfully." }
-
Home Page:
- Displays a list of books with pagination.
- Options to filter books by read/unread status.
-
Add Book Page:
- Form to add a new book.
-
Book Details Page:
- Displays detailed information about a selected book.
-
Search Functionality:
- Search bar to filter books by title or author.
- Used Bootstrap and jQuery to manage UI.
- Invalid Data: Ensures all required fields are provided and valid.
- API Errors: Returns descriptive error messages for failed requests.
- Install dependencies with
npm install
. - Start the server with
npm run dev
. - Access the app at
http://localhost:3000
in your web browser.
- Search by Title or Author:
- Added a search bar in the UI to filter books by title or author.
- Implemented corresponding API endpoints to support search functionality.
- Logging
- All activities (e.g., adding, updating, deleting books or error) are logged in a log file within the logs folder.
- Each log file is named based on the current date (e.g., 23_01_2025.log).
- Log entries include timestamps and a brief description of the activity.