This project is a simple Express.js application that provides a CRUD (Create, Read, Update, Delete) API for managing articles. It utilizes MongoDB as the database to store and retrieve article data. The application is built using modern JavaScript features and technologies.
Before running this application, make sure you have the following installed on your system:
- Node.js (https://nodejs.org/)
- MongoDB (https://www.mongodb.com/)
- Clone the repository:
git clone https://github.com/Al-Mansori/wiki-API
cd wiki-API- Install dependencies:
npm install-
Configure Environment Variables:
Create a
.envfile in the root directory and provide the necessary environment variables:DB_HOST=<MongoDB_Host> DB_PORT=<MongoDB_Port> DB_NAME=<Database_Name>
-
Start the Application:
node app.jsThe application will start and be accessible at http://localhost:3000.
- Endpoint:
GET /articles - Response: Returns a JSON array containing all articles in the database.
- Endpoint:
GET /articles/:articleTitle - Parameters:
articleTitle- The title of the article to retrieve. - Response: Returns a JSON object representing the specified article.
- Endpoint:
POST /articles - Request Body: JSON object with
titleandcontentfields. - Response: Returns the JSON object of the created article.
- Endpoint:
PUT /articles/:articleTitle - Parameters:
articleTitle- The title of the article to update. - Request Body: JSON object with updated
titleand/orcontentfields. - Response: Returns a message indicating the update status.
- Endpoint:
PATCH /articles/:articleTitle - Parameters:
articleTitle- The title of the article to update. - Request Body: JSON object with fields to be updated.
- Response: Returns a message indicating the update status.
- Endpoint:
DELETE /articles/:articleTitle - Parameters:
articleTitle- The title of the article to delete. - Response: Returns a message indicating the deletion status.
- Endpoint:
DELETE /articles - Response: Returns a message indicating the deletion of all articles.
- Express.js: Web application framework for building APIs.
- EJS: Templating engine for rendering views.
- MongoDB: NoSQL database for storing article data.
- Mongoose: MongoDB ODM for modeling and interacting with the database.
This project was developed as a learning exercise and follows basic CRUD operations using Express.js and MongoDB. It can be used as a starting point for more complex applications with additional features.