This is a Node.js API for managing persons with basic CRUD (Create, Read, Update, Delete) functionality. It allows you to easily create, retrieve, update, and delete person records in a MongoDB database.
Before you begin, ensure you have met the following requirements:
- Node.js: Make sure you have Node.js installed on your machine.
-
Clone the repository:
git clone <repository_url>
-
Navigate to the project directory:
cd nodejs-person-crud-api
-
Install dependencies:
npm install
-
Configure your MongoDB connection by creating a
.env
file in the root directory and adding your connection string:PORT=4500 connectDB=<your_mongodb_connection_string>
-
Start the server:
npm start
The API will be accessible at http://localhost:4500
.
- Endpoint:
POST /api
- Request Body:
{ "name": "John Doe" }
- Response:
{ "id": "<person_id>", "name": "John Doe" }
- Endpoint:
DELETE /api/:id
- Response:
{ "message": "Person deleted" }
- Endpoint:
PUT /api/:id
- Request Body:
{ "name": "Jane Smith" }
- Response:
{ "_id": "<person_id>", "name": "Jane Smith" }
- Endpoint:
GET /api/:id
- Response:
{ "_id": "<person_id>", "name": "John Doe" }
Describe how to use the API, provide code examples, and explain the expected behavior of each endpoint.
If you'd like to contribute to this project, please follow these guidelines:
- Fork the repository on GitHub.
- Create a new branch for your feature or bug fix.
- Make your changes, and test thoroughly.
- Create a pull request to the
main
branch of the original repository.