Royal Blogs TIA Backend is a RESTful API built using Node.js, Express, and Sequelize for managing a blogging platform. The API allows users to register, create posts, like/dislike posts, and comment on posts. It also includes routes for managing users and their authentication. The backend integrates image uploading via Cloudinary, handles authorization, and supports basic CRUD operations for blog posts, likes, dislikes, and comments.
User Authentication: Register, login, and verify user accounts.
Blog Posts: Create, read, update, and delete blog posts.
Comments: Add and fetch comments on blog posts.
Likes/Dislikes: Like or dislike posts, view all likes or dislikes.
Profile Management: View and update user profiles.
Installation
Environment Variables
Project Structure
API Routes
User Routes
Blog Post Routes
Comments Routes
Likes/Dislikes Routes
Models
Helper Functions
Technologies Used
License
To install and run the project locally:
git clone [email protected]:Akem-Ben/Royal_Blogs_TIA_Backend.git
cd Royal_Blogs_TIA_Backend
npm install
Create a .env file in the root directory and add the necessary environment variables (see the Environment Variables section).
npm run build
npm run dev
Create a .env file in the root directory with the following variables:
# DEVELOPMENT KEYS
DEV_PORT = YOUR DEV_PORT
DEV_DB_PORT = YOUR DEV_DB_PORT
DB_NAME = YOUR DB_NAME
DB_USERNAME = YOUR DB_USERNAME
DB_PASSWORD = YOUR DB_PASSWORD
DB_HOST = YOUR DB_HOST
# CLOUDINARY KEYS
CLOUDINARY_NAME = YOUR CLOUDINARY_NAME
API_KEY = YOUR API_KEY
API_SECRET = YOUR API_SECRET
# PRODUCTION KEYS
PROD_PORT = YOUR PROD_PORT
PROD_DB_NAME = YOUR PROD_DB_NAME
PROD_DB_USERNAME = YOUR PROD_DB_USERNAME
PROD_DB_PASSWORD = YOUR PROD_DB_PASSWORD
PROD_DB_HOST = YOUR PROD_DB_HOST
PROD_DB_PORT = YOUR PROD_DB_PORT
# GMAIL SMTP KEYS FOR MAILS
GMAIL_USER = YOUR GMAIL_USER
GMAIL_PASSWORD = YOUR GMAIL_PASSWORD
APP_BASE_URL = YOUR APP_BASE_URL
├── src
│ ├── configurations
│ ├── controllers
│ ├── helperFunctions
│ ├── middlewares
│ ├── models
│ ├── routes
│ ├── utilities
│ └── app.ts
├── package-lock.json
├── package.json
├── README.md
├── tsconfig.json
└── README.md
HTTP Method | Endpoint | Description |
---|---|---|
POST | /users/signup | Register a new user (requires profile image) |
POST | /users/verify/:token | Verify user email using a token |
POST | /users/login | Log in a user |
GET | /users/profile | Get the profile of the logged-in user (requires auth) |
POST | /users/resendVerification | Resend the verification email |
HTTP Method | Endpoint | Description |
---|---|---|
POST | /post/create | Create a new blog post (requires auth and image upload) |
GET | /post/singlePost/:postId | Get a single blog post |
DELETE | /post/deleteUserPost/:postId | Delete a blog post (requires auth) |
GET | /post/allPosts | Get all blog posts |
HTTP Method | Endpoint | Description |
---|---|---|
POST | /post/makeComment/:postId | Make a comment on a blog post (requires auth) |
GET | /post/allComments/:postId | Get all comments for a post |
HTTP Method | Endpoint | Description |
---|---|---|
POST | /post/likePost/:postId | Like a blog post (requires auth) |
GET | /post/allLikes/:postId | Get all likes for a blog post |
HTTP Method | Endpoint | Description |
---|---|---|
POST | /post/dislikePost/:postId | Dislike a blog post (requires auth) |
GET | /post/allDislikes/:postId | Get all dislikes for a blog post |
- User: Stores user details such as username, email, password, and profile image.
- BlogPost: Stores blog post information like title, image, text, likes, and dislikes.
- Comment: Stores comments made on blog posts.
- Likes: Tracks users who like a post.
- Dislikes: Tracks users who dislike a post.
- hashPassword: Hashes the user password using bcrypt.
- generateToken: Generates JWT tokens for authentication.
- convertToDDMMYY: Converts an ISO date to DD-MM-YY format.
- convertToISODateString: Converts a regular date string to ISO format.
- passwordTest: Validates the strength of user passwords using regex.
- Node.js
- Express.js
- TypeScript
- Sequelize ORM (for PostgreSQL)
- Cloudinary (for image uploads)
- Multer (for file uploads)
- JWT (for user authentication)
- Bcrypt (for password hashing)
- Nodemailer (for sending verification emails)