Sure! Here’s a sample README.md
file for your GitHub repository:
markdown
This is a simple backend application demonstrating CRUD (Create, Read, Update, Delete) operations using Node.js, Express, and MongoDB.
This project provides a basic setup for a backend service that handles CRUD operations on a product collection. It uses Node.js and Express for the server, and MongoDB for the database.
- Create a new product
- Retrieve all products
- Retrieve a single product by ID
- Update a product by ID
- Delete a product by ID
Before you begin, ensure you have the following installed:
- Node.js (v14.x or later)
- npm (v6.x or later)
- MongoDB (you can use a local instance or a cloud service like MongoDB Atlas)
-
Clone the repository:
git clone https://github.com/nostoc/simple-crud-app-backend.git cd simple-crud-app-backend
-
Install the dependencies:
npm install
-
Create a
.env
file in the root directory and add your MongoDB connection string:MONGODB_URI=your_mongodb_connection_string
-
Start the server:
npm run dev
-
The server will run on port 3003 by default. You can test the endpoints using Postman or any API client.
Here are the available API endpoints:
-
GET /api/products
- Retrieve all products.
- Response:
{ "products": [...] }
-
GET /api/products/:id
- Retrieve a product by ID.
- Response:
{ "product": { ... } }
-
POST /api/products
- Create a new product.
- Request body:
{ "name": "Product Name", "quantity": 10, "price": 100, "image": "image_url" }
- Response:
{ "product": { ... } }
-
PUT /api/products/:id
- Update a product by ID.
- Request body:
{ "name": "Updated Product Name", "quantity": 20, "price": 200, "image": "updated_image_url" }
- Response:
{ "product": { ... } }
-
DELETE /api/products/:id
- Delete a product by ID.
- Response:
{ "message": "Product deleted successfully" }
Contributions are welcome! Please fork the repository and create a pull request with your changes. Ensure your code follows the project's coding guidelines and includes appropriate tests.
This project is licensed under the ISC License. See the LICENSE file for more details.