Skip to content

Book library application where users can add books as read or unread.

Notifications You must be signed in to change notification settings

aabisht/nodebooklib

Repository files navigation

Book Library Application

Overview

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.

Features

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

Installation

  1. Clone the Repository

    git clone https://github.com/aabisht/nodebooklib.git
    cd nodebooklib
  2. Install Dependencies

    npm install
  3. Run the Application

    npm run dev
  4. Access the Application

    • Open your browser and navigate to http://localhost:3000.

API Endpoints

1. Create a Book

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

2. Get All Books

  • URL: /api/list
  • Method: GET
  • Query Parameters:
    • status (optional): read or unread.
    • 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"
        }
        {...}
      ]
    }

3. Get a Book

  • 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"
    }

4. Update Book Status

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

5. Delete a Book

  • URL: /api/delete
  • Method: DELETE
  • Request Body:
    {
      "id": <book-id>
    }
  • Response:
    {
      "success": true,
      "message": "Book with ID <book-id> removed successfully."
    }

UI Implementation

Pages and Features

  1. Home Page:

    • Displays a list of books with pagination.
    • Options to filter books by read/unread status.
  2. Add Book Page:

    • Form to add a new book.
  3. Book Details Page:

    • Displays detailed information about a selected book.
  4. Search Functionality:

    • Search bar to filter books by title or author.

Styling

  • Used Bootstrap and jQuery to manage UI.

Error Handling

  • Invalid Data: Ensures all required fields are provided and valid.
  • API Errors: Returns descriptive error messages for failed requests.

Steps to Run Locally

  1. Install dependencies with npm install.
  2. Start the server with npm run dev.
  3. Access the app at http://localhost:3000 in your web browser.

Bonus Features

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

About

Book library application where users can add books as read or unread.

Resources

Stars

Watchers

Forks

Packages

No packages published