A RESTful API built with Node.js, Express, and MongoDB for managing articles in a personal blog. This API supports basic CRUD (Create, Read, Update, Delete) operations and allows filtering articles by tags and publishing date.
- Create a new article
- Read a list of all articles or a single article by ID
- Update an existing article by ID
- Delete an article by ID
- Filter articles by tags or publishing date
- Node.js: Server-side JavaScript runtime
- Express.js: Web framework for Node.js
- MongoDB: NoSQL database for storing articles
- Mongoose: MongoDB ODM (Object Data Modeling)
- Dotenv: Manage environment variables
Before you begin, ensure you have the following installed:
Follow these steps to get the project running locally.
git clone https://github.com/pranavkrgupta/BlogAPI.git
cd BlogAPInpm installCreate a .env file in the root directory of the project and add the following variables:
MONGO_URI=your_mongodb_connection_stringnode server.jsEndpoint: POST /api/articles
Request Body:
{
"title": "Introduction to Node.js",
"content": "Node.js is a runtime environment for JavaScript...",
"tags": ["JavaScript", "Node.js", "Backend"]
}Endpoint: GET /api/articles?tags=JavaScript&date=2024-09-24
Endpoint: GET /api/articles/:id
Endpoint: PUT /api/articles/:id
Request Body (fields to update):
{
"title": "Updated Title"
}Endpoint: DELETE /api/articles/:id
.
├── models # MongoDB schemas and models
├── routes # API route definitions
├── .env # Environment variables
├── .gitignore # Files to ignore in version control
├── README.md # Project documentation
├── package.json # Project dependencies and scripts
└── server.js # Main server file