This project is a backend API for a Social Media Blogging Platform built using Node.js, Express, and MongoDB. It provides endpoints for managing users, admins, moderators, posts, comments, categories, saved posts, reports and etc. The system includes role-based access control, real-time notifications, and messaging features for enhanced user interaction. It also supports OTP-based authentication and Rotation Token authentication for secure operations and Socket.IO for real-time communication. πβ¨
-
π Authentication:
- Authentication with JWT rotation token
- User registration with OTP verification
- Role-based access control for users, moderators, admins, and superadmins
-
π₯ User Management:
- CRUD operations for users
- Follow/unfollow functionality
-
π‘οΈ Admin & Moderator Management:
- Superadmins can manage users, admins, and moderators
-
π Post Management:
- Create, update, delete, and fetch posts
- Like, unlike, and share posts
- Comment on posts
-
π¬ Comment Management:
- Add, update, delete, like, and unlike comments
-
π Saved Posts:
- Save and delete saved posts
-
π¨ Reports:
- Report users, posts, and comments
- Manage report statuses
-
π Notifications:
- Real-time notifications for likes, comments, follows, and messages
-
π Messaging:
- Send and receive messages in real-time
-
π Analytics:
- Track post views, likes, and shares
- Backend: Node.js, Express.js βοΈ
- Database: MongoDB, Mongoose ποΈ
- Authentication: JWT π
- Real-Time Communication: Socket.IO π
- Validation: Joi βοΈ
- File Uploads: Multer ποΈ
- Email Service: Nodemailer π§
- Security: Helmet, CORS, bcrypt.js π
- Environment Management: dotenv π±
- Node.js and npm installed π§°
- MongoDB installed and running locally or on a cloud service βοΈ
-
Clone the repository:
git clone https://github.com/chapi1234/Blog-App_social-media_website-express-backend-api cd Blog-App (social media) website express backend api -
Install dependencies:
npm install
-
Create a
.envfile in the root directory and add the following environment variables:PORT=5000 MONGODB=mongodb://localhost:27017/your-database-name SECRET_KEY=secretkey EMAIL=your-email@gmail.com EMAIL_PASSWORD=your-email-password
- Replace
your-email@gmail.comandyour-email-passwordwith your actual email credentials. βοΈ - Important: Ensure that your
.envfile is included in your.gitignorefile to prevent sensitive information from being exposed in version control.β οΈ
- Replace
-
Start the server:
npm startThe server will start running on http://localhost:5000 π
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register a new user |
| POST | /api/auth/login |
Login a user |
| POST | /api/auth/refresh |
Refresh token |
| POST | /api/auth/verify-otp |
Verify OTP for user registration |
| POST | /api/logout |
Logout |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/user/ |
Get all users |
| GET | /api/user/:id |
Get user by ID |
| PUT | /api/user/delete |
Update user by ID |
| DELETE | /api/user/:id |
Delete user by ID |
| POST | /api/user/follow/:id |
Following a user |
| DELETE | /api/user/unfollow/:id |
Unfollowing a user |
| GET | /api/user/followers/:id |
Getting all the followers |
| GET | /api/user/following/:id |
Getting all the followings |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/admin/ |
Get all admins |
| GET | /api/admin/:id |
Get admin by ID |
| GET | /api/admin/active |
Get all active admins |
| GET | /api/admin/inactive |
Get all inactive admins |
| PUT | /api/admin/:id |
Update admin by ID |
| DELETE | /api/admin/:id |
Delete admin by ID |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/moderator/ |
Get all moderators |
| GET | /api/moderator/:id |
Get moderator by ID |
| PUT | /api/moderator/:id |
Update moderator by ID |
| DELETE | /api/moderator/:id |
Delete moderator by ID |
| GET | /api/moderator/active |
Get active moderators |
| GET | /api/moderator/inactive |
Get inactive moderators |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/superadmin/create-admin |
Create a new admin |
| POST | /api/superadmin/create-moderator |
Create a new moderator |
| POST | /api/superadmin/activate-admin |
Activate admin |
| POST | /api/superadmin/activate-moderator |
Activate moderator |
| POST | /api/superadmin/deactivate-admin |
Deactivate admin |
| POST | /api/superadmin/deactivate-moderator |
Deactivate moderator |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/category/ |
Get all categorys |
| GET | /api/category/:id |
Get category by ID |
| POST | /api/category/ |
Add a new category |
| PUT | /api/category/:id |
Update category by ID |
| DELETE | /api/category/:id |
Delete category by ID |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/comment/ |
Get all comments |
| PUT | /api/comment/:id |
Update comment |
| DELETE | /api/comment/:id |
Delete comment |
| POST | /api/comment/like/:id |
Like a comment |
| POST | /api/comment/unlike/:id |
Unlike a comment |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/hashtag/:tag |
Get post by tag |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/message/ |
Get all messages |
| GET | /api/message/:id |
Get message by ID |
| POST | /api/message/ |
Add a new message |
| PUT | /api/message/:id |
Update message by ID |
| DELETE | /api/message/:id |
Delete message by ID |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/notification/ |
Get all notifications |
| POST | /api/notification/ |
Add a new notification |
| PATCH | /api/notification/:id |
Update notification by ID |
| DELETE | /api/notification/:id |
Delete notification by ID |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/post/create |
create a new post |
| GET | /api/post/all |
Get all posts |
| GET | /api/post/single/:id |
Get post by ID |
| GET | /api/post/user/:id |
Get a user posts |
| PUT | /api/post/update/:id |
Update post by ID |
| DELETE | /api/post/delete/:id |
Delete post by ID |
| POST | /api/post/like/:id |
Like a post |
| POST | /api/post/unlike/:id |
unlike a post |
| POST | /api/post/share:id |
Share a post |
| POST | /api/post/comment/:id |
Comment on a post |
| GET | /api/post/comment/:id |
Get comments on a post |
| Method | Endpoint | Description |
|---|---|---|
| PUT | /api/report/:id |
Update report by ID |
| GET | /api/report/ |
Get all reports |
| GET | /api/report/:id |
Get report by ID |
| POST | /api/report/ |
Add a new report |
| DELETE | /api/report/:id |
Delete report by ID |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/savedpost/ |
Get all savedposts of the user |
| POST | /api/savedpost/ |
Create a new savedpost |
| DELETE | /api/savedpost/:id |
Delete savedpost by ID |
π
βββ node_modules
βββ controller
β βββ adminController.js
β βββ authController.js
β βββ categoryController.js
β βββ commentController.js
β βββ followController.js
β βββ hashtagController.js
β βββ messageController.js
β βββ moderatorController.js
β βββ notificationController.js
β βββ postController.js
β βββ reportController.js
β βββ savedController.js
β βββ superadminController.js
β βββ userController.js
βββ functions
β βββ uploadFile.js
βββ models
β βββ Admin.js
β βββ Analytics.js
β βββ Category.js
β βββ Comment.js
β βββ Follower.js
β βββ Message.js
β βββ Notification.js
β βββ Post.js
β βββ Report.js
β βββ SavedPost.js
β βββ SuperAdmin.js
β βββ Token.js
β βββ User.js
βββ middleware
β βββ verifyToken.js
βββ routes
β βββ admin.js
β βββ auth.js
β βββ category.js
β βββ comment.js
β βββ hashtag.js
β βββ message.js
β βββ moderator.js
β βββ notification.js
β βββ post.js
β βββ report.js
β βββ savedpost.js
β βββ superadmin.js
β βββ user.js
βββ validation
β βββ validation.js
βββ .env
βββ index.js
βββ .gitignore
βββ .package-lock.json
βββ .package.json
βββ .README.md
βββ Server.js
βββ superadmin.json
βββ testSocketClient.js- Send a message to another user.
- Receive a message in real-time.
- Receive notifications in real-time.
To test the Client side socket connection
node testClientSocket.jsContributions are welcome! π Please fork the repository and create a pull request with your changes. π₯
This project is licensed under the MIT License π
Developed by Metasebiyaw Asfaw. For any inquiries, feel free to contact me at metasebiyawasfaw@gmail.com π©