Skip to content

hanpm/Book-API

Repository files navigation

Book-API

Creating an API with Node.js, Express, and MongoDB to manage a collection of books.

Project Description

Technologies Used

Technology used in this project are Node.js, Express, and MongoDB.

Features to implement in the future

There are couple things that I came in mind when completing (& researching) for this project.

  1. Implementing more features to the API
  • I frequent the library a lot and here's some useful features to include:
    • Adding genres and sorting by genres.
    • Having a count of each inventory.
  1. Refactoring with better MVC architecture
  • Adhering to a structured architecture is important for creating scalable, reusable, and organized applications. I have already began to separate the code into its appropriate folders. With more time, I would better organize my code according to the embedded link.
  1. Complete the MERN stack
  • Currently, this project is only a part of the MERN stack.
  • We need to also implement a frontend, React, to complete this stack and make this project a full-stack application.
  1. Fix my unit test (book.test.js)
  • This is my first time writing unit test with Jest. I can't seem to figure out how to stop "asynchronous operations" in my test. Therefore, the test fails, but nonetheless, I decided to put my attempt here.

How to install and run project

This guide will walk you through the steps to run an API built with Node.js, Express, and MongoDB.

Prerequisites

Before you begin, ensure you have the following installed on your system:

  • Node.js: Download and install Node.js from nodejs.org.

Installation

  1. Clone the repository of your Node.js API project or download into your computer and save into your Desktop
    git clone https://github.com/hanpm/Book-API.git
    
  2. Navigate to the project directory.
    cd Desktop/Book-API
    
  3. Install dependencies
    npm install 
    

Running the API

  1. Run the server
    npm run dev 
    
  2. Download Postman or Insomnia & start making request to the API
  • Get all books
    localhost:3000/books
    
  • Get books with pagination
    localhost:3000/books?page=4&limit=10
    
  • Get book by ID
    localhost:3000/books/<insert ID>
    
  • Post books
    localhost:3000/books
    
    {
    "title": "Insert title",
    "author": "Insert author",
    "publicationYear": 0
    }
    
  • Update books
    localhost:3000/books/<insert ID>
    
    {
    "title": "Insert updated title",
    "author": "Insert updated author",
    "publicationYear": 0
    }
    
  • Search books
    localhost:3000/books/search?q=maryshelley&page=4&limit=10
    
  • Get book stats
    localhost:3000/books/stats
    

Test and how to run them

  1. Install dependencies
    npm install --save-dev jest
    
  2. Run test in terminal
     npx jest

About

Creating an API with Node.js, Express, and MongoDB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published