This repository contains the backend code for a RESTful API built using Express.js and MongoDB to manage a blog. This API allows you to perform CRUD operations (Create, Read, Update, Delete) on blog posts, providing a simple way to interact with blog content.
Technology Used- ExpressJs, MongoDB, RestAPI
- Create new blog posts with titles, content, and other details.
- Retrieve a list of all blog posts or specific post details.
- Update blog post information.
- Delete blog posts from the database.
- Node.js and npm should be installed on your machine.
- MongoDB should be installed and running.
-
Clone the repository:
git clone https://github.com/vickytilotia/ExpressJS-MongoDB-RestAPI-Blog.git
-
Navigate to the project directory:
cd ExpressJS-MongoDB-RestAPI-Blog
-
Install dependencies:
npm install
-
Create a
.env
file and set the following environment variables:PORT=3000 MONGODB_URI=your_mongodb_connection_uri
-
Start the server:
npm run server
-
The API will be accessible at
http://localhost:3000
.
- `GET /api/posts`: Get a list of all blog posts.
- `GET /api/posts/:id`: Get details of a specific blog post by ID.
- `POST /api/posts`: Create a new blog post.
- `PUT /api/posts/:id`: Update details of a specific blog post by ID.
- `DELETE /api/posts/:id`: Delete a blog post by ID.
Contributions are welcome! If you find any issues or want to enhance the project, feel free to create a pull request.
- Fork the repository.
- Create a new branch for your feature:
git checkout -b feature-name
. - Commit your changes:
git commit -am 'Add feature'
. - Push to the branch:
git push origin feature-name
. - Submit a pull request.