blog-website is one of my personal projects where registered bloggers write blogs. Bloggers can also comment or react to blogs. 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 lets-blog.netlify.app/all_blogs
- bloggers can create their profiles (token-based authentication)
- bloggers can edit their profile
- bloggers can write blogs. They can set the category of their blog (i.e. travel, medical, tech etc)
- registered bloggers can comment on their own or others blog
- registered bloggers can also react on others blog. They can react like, love, sad, haha, informative to blogs
- unregistered public users can read blogs but can't comment or react n blogs
- Blogs of a particular category can be viewed
Runtime environment
- Node.js
Database
- MongoDB
Image storage service
- Cloudinary
Testing framework
- Jest
Containerization 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/blog-website-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.exampleon 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
.envfile 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.examplefile while adding new constants to the.envfile.
-
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 letsblog-api-c
-
To run tests, first enter within the API container
- on windows CMD (not switching to bash)
docker exec -it letsblog-api-c /bin/sh - on windows CMD (after switching to bash)
or
docker exec -it letsblog-api-c //bin//shwinpty docker exec -it letsblog-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:
GET localhost:3000/user/login - Edit user profile:
PUT localhost:3000/user/editProfile - Refresh tokens:
POST localhost:3000/user/me/refresToken - Get loggedin user's info:
GET localhost:3000/user/me - Get blogger's info:
GET localhost:3000/user/bloggerProfile/:bloggerId
- Create a new category:
POST localhost:3000/category - Get list of all categories:
GET localhost:3000/category - Get list of all categorized blog counts of user:
GET localhost:3000/category/categorizedBlogs/:bloggerId
- Create a new blog:
POST localhost:3000/blog - Get list of all blogs with pagination of certain category of a user:
GET localhost:3000/blog/:bloggerId?/:categoryId? - Get details of a blog:
GET localhost:3000/blog/:blogId - Get list of all blogs of a selected category:
GET localhost:3000/blog/category/:categoryId - React to a blog:
PUT localhost:3000/blog/react - Comment to a blog:
POST localhost:3000/blog/comment - Delete a comment:
DELETE localhost:3000/blog/comment