A REST API built with Express.js and Mongoose for connecting to MongoDB. This application provides user authentication and CRUD operation for a Blog Managment System.
- RESTful API endpoints
- MongoDB integration with Mongoose
- JWT authentication
- Rate limitting Middleware
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- npm (v6 or higher)
- MongoDB (v4.4 or higher) or MongoDB Atlas account
- API testing tool (e.g., Postman, Insomnia)
-
Clone the repository
git clone https://github.com/ShivankSharma070/BlogManagmentBackend.git cd BlogManagmentBackend/
-
Install dependencies
npm install
-
Set up environment variables
- Create a
.env
file in the root directory - Add your configuration (see Configuration)
- Create a
-
Start the server
npm start
Create a .env
file with these variables:
PORT=3000
MONGODB_CONNECT_URL="<your-mongodb-connection-url>"
JWT_PRIVATE_KEY="<Your-private-key>"
Replace MONGODB_CONNECT_URL
with your MongoDB connection string (use MongoDB Atlas URI for cloud databases) and JWT_PRIVATE_KEY
with a private key you want to use for you JWT authentication.
-
Development mode :
npm run dev
-
Production mode:
npm start
The server will be available at http://localhost:3000
by default.
Method | Endpoint | Description |
---|---|---|
POST | /auth/login |
Login using email and password |
POST | /auth/register |
Register new user. |
GET | /auth/logout |
Logout current user. |
GET | /blog/s |
Get items by ID/Name |
POST | /blog/add |
Create a new blog |
PUT | /blog/update |
Update an existing blog by ID |
DELETE | /blog/delete |
Delete an blog by ID |
POST | /blog/comment |
Add comments to a blog by ID |
GET | /blog/like |
Like a blog by ID |
/auth/login
Request Body should contain a json containing email and password
{
"email":"<user-email>",
"password":"<user-password>"
}
/auth/logout
/auth/register
Request body should have a json object like this
{
"name":"<user-name>",
"email":"<user-email>",
"password":"<user-password>"
}
/blog/s?query="yourQuery"
Parameter | Description |
---|---|
id | Blog unique id |
query | Query used to search Blog titles |
/blog/add
Request body should contains a json like
{
"title":"Blog title",
"content":"Blog Content"
}
/blog/update?id="blog-id"
Parameter | Description |
---|---|
id | Unique id for blog |
Request Body should contain a json with fields to update. For example
{
"title":"<new-title>"
}
/blog/delete?id="blog-id"
Parameter | Description |
---|---|
id | Unique id for blog |
/blog/comment?id="blog-id"
Parameter | Description |
---|---|
id | Unique id for blog |
Request Body should contain a json with comments for a blog. For example
{
"comment":"Nice Blog"
}
These comments can be a string or a array of strings
/blog/like?id="blog-id"
Parameter | Description |
---|---|
id | Unique id for blog |
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Note: Replace all placeholder values (your-username, your-repo-name, etc.) with your actual project details. Update API endpoints and validation rules according to your specific application requirements.