MVBlog is a robust blog management application designed to handle user authentication and blog post management. The platform allows users to register, log in, create, and manage their blog posts with support for file uploads. It leverages modern technologies such as JWT for secure authentication, bcrypt for password hashing, and PostgreSQL for efficient data storage.
- User Registration and Login
- JWT-Based Authentication
- Create, Read, Update, and Delete (CRUD) Operations for Blog Posts
- File Uploads for Blog Posts
- View All Posts and Manage User-Specific Posts
- Node.js with Express: Backend server and API handling.
- PostgreSQL: Database for storing user and blog post data.
- Bcrypt: For secure password hashing.
- JWT: For managing authentication tokens.
- Multer: Middleware for handling file uploads.
- Cors: Middleware for Cross-Origin Resource Sharing.
- dotenv: For managing environment variables.
- Cookie-Parser: For handling cookies.
- Node.js: The runtime environment used for the server-side code.
- Express: The web framework used to build the API.
- PostgreSQL: The database system used to store data.
- JWT: JSON Web Tokens used for authentication.
- bcrypt: Library used for hashing passwords.
- Multer: Middleware for handling file uploads.
- File Uploads: Feature of the application to handle image and file uploads.
- Web Application: A general term for applications accessed via web browsers.
- API: Application Programming Interface, a crucial part of the project.
- Authentication: The process of verifying user identity.
- Blog: The primary functionality of the project.
- Full Stack: The project involves both frontend and backend components.
- Open Source: Indicates that the project is open for public contributions.
- JavaScript: The programming language used.
- Backend: Refers to the server-side part of the application.
- CRUD: Create, Read, Update, Delete operations.
- REST API: Representational State Transfer API, a common architectural style for web services.
- Middleware: Functions that execute during the request-response cycle.
- Cors: Middleware for enabling Cross-Origin Resource Sharing.
- Dotenv: Library for managing environment variables.
- Node.js and npm should be installed.
- PostgreSQL should be installed and running.
-
Clone the Repository:
git clone https://github.com/Manish312002/MVBLOG.git cd MVBLOG
-
Install Dependencies:
- Install the necessary npm packages:
cd client npm i cd server npm i
-
Setup Environment Variables:
- Create a .env file in the root directory of the project and add the following environment variables:
SECRET=your_jwt_secret PG_USER=your_postgres_user PG_HOST=localhost PG_DATABASE=your_postgres_database PG_PASSWORD=your_postgres_password PG_PORT=5432
- Replace the placeholder values with your actual configuration details.
- Run the Server:
-
Start the server:
cd client npm run dev cd server nodemon server.js
-
-
POST /register
Registers a new user.
- Request Body:
{ "username": "string", "email": "string", "password": "string" }
- Response:
- Success:
{ "message": "User has been registered" }
- Error:
{ "message": "Username already exists!" // or other error messages }
- Success:
- Request Body:
-
POST /login
Logs in a user and returns a JWT token.
- Request Body:
{ "username": "string", "password": "string" }
- Response:
- Success:
{ "id": "number", "username": "string" }
- Error:
{ "message": "Incorrect password" // or "User not found, Try again!" }
- Success:
- Request Body:
-
GET /profile
Retrieves the profile information of the logged-in user (requires authentication).
- Headers:
- Cookie:
token=<jwt_token>
- Cookie:
- Response:
- Success:
{ "username": "string", "id": "number" }
- Error:
{ "message": "No token provided" // or "Invalid token" }
- Success:
- Headers:
-
POST /logout
Logs out the current user by clearing the JWT token.
- Response:
- Success:
{ "message": "Logout" }
- Success:
- Response:
-
POST /create_post
Creates a new blog post (requires authentication).
- Request Body:
{ "title": "string", "contentType": "string", "summary": "string", "content": "string" }
- File Upload:
- File:
file
(optional)
- File:
- Headers:
- Cookie:
token=<jwt_token>
- Cookie:
- Response:
- Success:
{ "message": "Success" }
- Error:
{ "message": "Error message here" // Specific error message }
- Success:
- Request Body:
-
GET /posts
Retrieves a list of blog posts, sorted randomly and limited to 20.
- Response:
- Success:
[ { "id": "number", "title": "string", "contentType": "string", "summary": "string", "author": "string", "content": "string", "filepath": "string" } ]
- Success:
- Response:
-
GET /my_Posts
Retrieves blog posts created by the logged-in user (requires authentication).
- Headers:
- Cookie:
token=<jwt_token>
- Cookie:
- Response:
- Success:
[ { "id": "number", "title": "string", "contentType": "string", "summary": "string", "author": "string", "content": "string", "filepath": "string" } ]
- Error:
{ "message": "No token provided" // or "Invalid token" }
- Success:
- Headers:
-
GET /delete/:id
Deletes a blog post by ID (requires authentication).
- Parameters:
- Path Parameter:
id
(Post ID)
- Path Parameter:
- Headers:
- Cookie:
token=<jwt_token>
- Cookie:
- Response:
- Success:
{ "message": "Post {id} deleted" }
- Error:
{ "message": "Error message here" // Specific error message }
- Success:
- Parameters:
-
GET /post/:id
Retrieves a single blog post by ID.
- Parameters:
- Path Parameter:
id
(Post ID)
- Path Parameter:
- Response:
- Success:
{ "id": "number", "title": "string", "contentType": "string", "summary": "string", "author": "string", "content": "string", "filepath": "string" }
- Error:
{ "message": "Failed to get post" // or other error messages }
- Success:
- Parameters:
-
GET /edit/:id
Retrieves the details of a blog post for editing by ID.
- Parameters:
- Path Parameter:
id
(Post ID)
- Path Parameter:
- Response:
- Success:
{ "id": "number", "title": "string", "contentType": "string", "summary": "string", "author": "string", "content": "string", "filepath": "string" }
- Error:
{ "message": "Failed to get post" // or other error messages }
- Success:
- Parameters:
-
POST /edit/:id
Edits an existing blog post by ID (requires authentication).
- Request Body:
{ "title": "string", "contentType": "string", "summary": "string", "content": "string" }
- File Upload:
- File:
file
(optional)
- File:
- Parameters:
- Path Parameter:
id
(Post ID)
- Path Parameter:
- Headers:
- Cookie:
token=<jwt_token>
- Cookie:
- Response:
- Success:
{ "message": "Success" }
- Error:
{ "message": "Failed to Update post" // or other error messages }
- Success:
- Request Body:
- We welcome contributions to BlogMaster! To contribute:
- Fork the repository.
- Create a new branch (git checkout -b feature-branch).
- Make your changes.
- Commit your changes (git commit -am 'Add new feature').
- Push to the branch (git push origin feature-branch).
- Open a pull request.