# CRUD Using Mongoose
## Overview
This repository contains a simple CRUD (Create, Read, Update, Delete) application built with Node.js and Mongoose, designed to provide an efficient and straightforward way to manage data in a MongoDB database. The application demonstrates how to perform basic database operations using Mongoose as an Object Data Modeling (ODM) library.
## Features
- Create, Read, Update, and Delete operations on data
- Simple RESTful API design
- Mongoose for MongoDB interaction
- Built-in data validation
- Express framework for handling requests
- JSON response format
- Error handling and logging
## Technologies Used
- **Node.js**: JavaScript runtime for server-side programming
- **Express.js**: Web framework for Node.js
- **Mongoose**: ODM for MongoDB and Node.js
- **MongoDB**: NoSQL database to store data
- **Nodemon**: Tool for automatically restarting the server during development
## Installation
To get a copy of this project up and running on your local machine, follow these steps:
### Prerequisites
- Node.js (v12 or higher)
- MongoDB installed locally or access to a MongoDB Atlas account
### Steps
1. Clone the repository:
```bash
git clone https://github.com/yourusername/CRUD-using-Mongoose.git-
Navigate to the project directory:
cd CRUD-using-Mongoose -
Install the dependencies:
npm install
-
Configure your MongoDB connection:
- Open
config.jsand update theMONGO_URIvariable with your MongoDB connection string.
- Open
-
Start the server:
npm start
-
The application should now be running on
http://localhost:3000.
- Endpoint:
POST /api/items - Request Body:
{ "name": "Item Name", "description": "Item Description" } - Response:
- Success:
201 Created - Error:
400 Bad Request
- Success:
- Endpoint:
GET /api/items - Response:
- Success:
200 OKwith an array of items
- Success:
- Endpoint:
GET /api/items/:id - Response:
- Success:
200 OKwith the item object - Error:
404 Not Found
- Success:
- Endpoint:
PUT /api/items/:id - Request Body:
{ "name": "Updated Item Name", "description": "Updated Item Description" } - Response:
- Success:
200 OKwith the updated item object - Error:
400 Bad Requestor404 Not Found
- Success:
- Endpoint:
DELETE /api/items/:id - Response:
- Success:
204 No Content - Error:
404 Not Found
- Success:
You can use tools like Postman or CURL to test the API endpoints. Make sure to set the request method and URL according to the specified endpoints.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or features you would like to add.