book-search is one of my personal projects where anyone can search for books related to programming, IT or technology. Registered user can also add books to their favourite list. This repository holds the code of it's backend which is a RESTful API.
The frontend of this project can be found here (Angular).
Visit complete live project book-search241.netlify.app
- Users can create their profiles (token-based authentication)
- Users can search for books by title, author or keywords
- Users can view details of a particular book
- Users can add books to their favorite list
- Users can remove books from their favorite list
- Users can view their list of favorite books
Runtime environment
- Node.js
API for books
Database
- MongoDB
Containerized tool
- Docker
- Navigate & open CLI into the directory where you want to put this project & Clone this project using this command.
git clone https://github.com/tazbin/book-search-backend-nodejs-REST-API.git
- Download repository
- Extract the zip file, navigate into it & copy the folder to your desired directory
- There is a file named
.env.example
on the root directory of the project - Create a new file by copying & pasting the file on the root directory & rename it to just
.env
- The
.env
file is already ignored, so your credentials inside it won't be committed - Change the values of the file. Make changes of comment to the
.env.example
file while adding new constants to the.env
file.
-
To build docker image
docker compose build --no-cache
-
To run the containers in detached mode (wait for a while for database connection)
docker compose up -d
-
To view running containers
docker container ps
-
To view API logs
docker logs booksearch-api-c
-
To run tests, first enter within the API container
- on windows CMD (not switching to bash)
docker exec -it booksearch-api-c /bin/sh
- on windows CMD (after switching to bash)
or
docker exec -it booksearch-api-c //bin//sh
winpty docker exec -it booksearch-api-c //bin//sh
now run test command
npm test
- on windows CMD (not switching to bash)
-
To exit from API container, press Ctrl+D on terminal
-
To stop the containers
docker compose down
- Authentication required
- Authentication not required
- Resgister:
POST localhost:3000/user/register
- Login:
POST localhost:3000/user/login
- Logout:
DELETE localhost:3000/user/logout
- Refresh token:
POST localhost:3000/user/me/tokenRefresh
- Get loggedin user's info:
GET localhost:3000/user/me/getLoggedInUserData
- Search for books:
GET localhost:3000/book/search/:searchParams/:page
- Get details of a particular book:
GET localhost:3000/book/getBookDetails/:bookId
- Add a book to user's favourite list:
POST localhost:3000/book/addToFavourite
- Remove a book from user's favourite list:
DELETE localhost:3000/book/removeFromFavourite
- Get user's favourite book list:
GET localhost:3000/book/getFavouriteBooks