Skip to content

Flashing through MongoDB and Express Concepts with Restful API

Notifications You must be signed in to change notification settings

Miltonnare/Exprees_JS-MongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Bookstore API

A simple Node.js + Express + MongoDB API for managing books in a bookstore. It supports inserting, retrieving, filtering, and aggregating book data.

πŸ“¦ Project Structure

Bookstore/
β”œβ”€β”€ db.js ### MongoDB connection and utility functions
β”œβ”€β”€ books.js ### Book-related database operations
β”œβ”€β”€ app.js ### Express server and route handlers
β”œβ”€β”€ package.json
└── README.md

πŸš€Features

Add a new book

Get all books

Filter books by author and genre

List books that are in stock

Calculate average price per genre

βš™οΈ Setup Instructions

Clone the repo

git clone (https://github.com/Miltonnare/Exprees_JS-MongoDB.git)

cd Exprees_JS-MongoDB

Install dependencies

npm install

Start MongoDB (ensure it's running locally on mongodb://localhost:27017)

Run the server

node app.js

Or with nodemon:

nodemon app.js

Server will be running at:

http://localhost:3000

πŸ§ͺ Testing the API with Postman

  1. Insert a Book

Endpoint: POST /books/insertBook

Body (JSON):

{ "title": "Atomic Habits", "author": "James Clear", "genre": "Self-help", "price": 19.99, "inStock": true }

  1. Get All Books

Endpoint: GET /books/getAllBooks

  1. Get Books by Author and Genre

Endpoint: GET /books/getBooksByAuthor

Query Params:

author=James Clear&genre=Self-help

Example:

GET http://localhost:3000/books/getBooksByAuthor?author=James%20Clear&genre=Self-help

  1. Get In-Stock Books

Endpoint:GET /books/inStock

  1. Get Average Price by Genre

Endpoint: GET /books/averagePriceByGenre

πŸ“Œ Notes

MongoDB database name: Bookstore

Collection used: Books

You must ensure MongoDB is running and accessible at mongodb://localhost:27017.

About

Flashing through MongoDB and Express Concepts with Restful API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published