# 🚀 Simple User CRUD API with Express.js This is a beginner-friendly Node.js project that demonstrates how to perform full CRUD (Create, Read, Update, Delete) operations using **Express.js** and **Postman**. It stores user data in a local mock JSON file (`MOCK_DATA.js`) and dynamically updates it using Node's file system. --- ## 📦 Features - ✅ `GET /api/users` — Fetch all users - ✅ `GET /api/users/:id` — Fetch a specific user by ID - ✅ `POST /api/users` — Create a new user - ✅ `PATCH /api/users/:id` — Update an existing user - ✅ `DELETE /api/users/:id` — Delete a user All API endpoints can be tested using **Postman**. --- ## 🛠 Tech Stack - **Node.js** - **Express.js** - **JavaScript Modules** - **File System (`fs`)** for persistent storage - **Postman** for API testing --- ## 📁 File Structure . ├── index.js # Main server file ├── MOCK_DATA.js # Array of user objects (export default [...]) ├── package.json # Dependencies and script info
--- ## 📦 Installation & Setup 1. **Clone the repo** ```bash git clone https://github.com/your-username/express-crud-api.git cd express-crud-api -
Install dependencies
npm install
-
Start the server
npm start
-
The server runs at:
http://localhost:3000
- Method:
GET - URL:
http://localhost:3000/api/users - Response: JSON array of all users
- Method:
GET - URL:
http://localhost:3000/api/users/1 - Response: JSON of that specific user
- Method:
POST - URL:
http://localhost:3000/api/users - Body: (raw JSON)
{ "first_name": "Yasra", "last_name": "Khan", "email": "yasra@example.com" }- Response: Newly created user with an auto-incremented
id
- Method:
PATCH - URL:
http://localhost:3000/api/users/1 - Body: (raw JSON)
{ "email": "yasra.updated@example.com" }- Response: Updated user data
- Method:
DELETE - URL:
http://localhost:3000/api/users/1 - Response: Confirmation + deleted user info
- Visit
http://localhost:3000/usersto see a simple HTML list of users rendered on the browser.
- How to set up and use Express routes
- How to read and write to files using Node’s
fsmodule - How to test backend APIs using Postman
- How CRUD works at the API level
- Add validation for required fields
- Use UUIDs instead of numeric IDs
- Move to a
.jsonfile instead of.js - Connect to a real database (e.g. MongoDB)
Yasra Kashif
This project is open source and available under the MIT License.
--- ## 🧩 Add This to Your `package.json` (if not already): ```json "scripts": { "start": "node index.js" }