Skip to content

meanii/book-management

Repository files navigation

book-management 🦉

book management api, using express and mongodb

Table of contents

Deployed on Digital Ocean Server: https://book-management.meanii.dev/books

Demo Video: https://www.youtube.com/watch?v=IKx0A9xu6TE

How to run

There are two ways to run this project

  1. legacy way
  2. using docker compose (recommended)

How to run legacy way

You need to have nodejs and mongodb installed on your machine

  1. Clone this repository
git clone https://github.com/meanii/book-management
  1. Install dependencies
npm install
  1. Run server
npm start

How to run using docker compose

You need to have docker and docker-compose installed on your machine

  1. Install docker and docker-compose
curl -o- https://get.docker.com | sh -x 
  1. Clone this repository
git clone https://github.com/meanii/book-management
  1. Run docker-compose
docker compose up

API Documentation

Books

Get all books

default limit is 10, you can change it by adding limit query parameter

GET /books
GET /books?limit=20&page=2

Get book by id

GET /books/:id

Create new book

POST /books
{
    "title": "string",
    "author": "string",
    "summary": "string"
}

Update book

PUT /books/:id
{
    "title": "string",
    "author": "string",
    "summary": "string"
}

Delete book

DELETE /books/:id

How to Deploy on Server

pre-requisite:

  • VPS Server (Digital Ocean, AWS, etc)
  • OS: Ubuntu 20.04 LTS (recommended)
  • Domain Name (optional)
  • Docker and Docker Compose installed on your server
  • Git installed on your server
  • Nginx installed on your server
  • SSL Certificate (optional)

You need to have docker and docker-compose installed on your server

  1. Install docker and docker-compose
curl -o- https://get.docker.com | sh -x 
  1. Clone this repository
git clone https://github.com/meanii/book-management && cd book-management
  1. Run docker-compose
docker compose up -d

useful docker and docker compose commands:

docker ps # show running containers
docker ps -a # show all containers
docker compose ps # show running containers using docker compose
docker compose logs --follow --tail 100 # show logs of all containers using docker compose
docker logs <container-id> # show logs of a container
docker exec -it <container-id> bash # enter a container
  1. Install Nginx
sudo apt update
sudo apt install nginx
  1. Configure Nginx use nginx.conf as a template
sudo vim /etc/nginx/sites-available/book-management.conf
  1. Enable Nginx config
sudo ln -s /etc/nginx/sites-available/book-management.conf /etc/nginx/sites-enabled/
  1. Restart Nginx
sudo systemctl restart nginx
  1. Install SSL Certificate (optional)
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

License

The Unlicense