This is a sample project for a book and author management application using Node.js, Express.js, and MongoDB. It implements a basic CRUD (Create, Read, Update, Delete) API for managing books and authors
To run this project, you'll need to have Node.js and MongoDB installed on your system. Follow these steps:
- Clone this repository.
- Navigate to the project directory in your terminal.
- Install dependencies by running the command:
npm install
- Start the server with:
node server.js
Action | Endpoint | Description |
---|---|---|
List Books | http://localhost:3000/books | Endpoint to list all books |
List Authors | http://localhost:3000/authors | Endpoint to list all authors |
Add Book | http://localhost:3000/books | Send a POST request with book details in JSON |
Add Author | http://localhost:3000/authors | Send a POST request with author details in JSON |
Update Book | http://localhost:3000/books/:id | Send a PUT request with updated book details |
Update Author | http://localhost:3000/authors/:id | Send a PUT request with updated author details |
Delete Book | http://localhost:3000/books/:id | Send a DELETE request to delete a book |
Delete Author | http://localhost:3000/authors/:id | Send a DELETE request to delete an author |
Search and Filtering Books | http://localhost:3000/books/search | Send a GET request to search and filter books |
Add book to favorite List | http://localhost:3000/books/AddFavoriteList | Send a PUSH to favorit List |
Get Favorite | http://localhost:3000//books/AddFavoriteList | Endpoint to list favotire List |
This project follows the MVC (Model-View-Controller), which helps in organizing the codebase into separate components. Here's a brief overview of the project's structure:
project-root-directory
├── src
│ ├── app.js
│ ├── config
│ │ └── dbConfig.js
│ ├── Err
│ │ ├──badRequest.js
│ │ ├──baseErr.js
│ │ ├── notfound.js
│ │ └──validationerr.js
│ ├── controllers
│ │ ├── AuthoresController.js
│ │ └── booksController.js
│ ├── middleware
│ │ ├── errorHandling.js
│ │ ├── Handler404.js
│ └── pagination.js
│ ├── models
│ │ ├── Author.js
│ │ ├── Books.js
│ │ ├──globalValidation.js
│ │ └──index.js
│ └── routes
│ ├── index.js
│ ├── booksRoutes.js
│ └──authorsRoutes.js
├── package.json
├── .eslintrc.json
├── Server.js
└── README.md
This API uses JSON (JavaScript Object Notation) for data exchange. When interacting with the API, ensure that your requests and responses are formatted in JSON. Below are examples of the JSON structures for books and authors:
[
{
"_id": "64fa88ef1c468255e84dce64",
"title": "To Kill a Mockingbird",
"author": {
"_id": "64fa88a81c468255e84dce61",
"name": "Harper Lee"
},
"publisher": "J.B. Lippincott & Co.",
"pageCount": 281,
}
]
You can use Postman to test the API endpoints. Import the provided Postman collection for easy testing.
Feel free to open issues or send pull requests for improvements.
This project is licensed under the MIT License.