https://github.com/mayankghatawal/usermanagement
User Management REST API
https://github.com/mayankghatawal/usermanagement
expressjs mongodb mongoose nodejs postman
Last synced: 2 months ago
JSON representation
User Management REST API
- Host: GitHub
- URL: https://github.com/mayankghatawal/usermanagement
- Owner: MayankGhatawal
- Created: 2025-09-30T14:46:05.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-09-30T16:31:04.000Z (9 months ago)
- Last Synced: 2025-09-30T16:31:33.313Z (9 months ago)
- Topics: expressjs, mongodb, mongoose, nodejs, postman
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# User Management REST API
A simple RESTful API built with **Node.js**, **Express**, and **MongoDB (Mongoose)** for managing users (Create, Read, Update, Delete).
This project includes email and mobile validation, proper error handling, and follows a clean file structure.
---
## 🚀 Features
The API provides the following endpoints for the `User` resource:
| Method | Endpoint | Description |
|--------|----------------|------------------------------------|
| POST | `/api/addUser` | Create a new user (name, email, mobile) |
| GET | `/api/getUsers` | Get all users |
| GET | `/api/getUser/:id` | Get a single user by ID |
| PUT | `/api/updateUser/:id` | Update a user by ID |
| DELETE | `/api/deleteUser/:id` | Delete a user by ID |
---
## ✅ Requirements & Specifications
- Implement **CRUD operations** for the User resource.
- Use **JSON** format for request and response.
- Validate required fields:
- `email` must have a valid format.
- `mobile` must be unique.
- Proper **status codes** and **error handling**.
- Clean and modular code.
---
## 🛠️ Technology Stack
- **Backend:** Node.js, Express.js
- **Database:** MongoDB
- **ODM:** Mongoose
---
## ⚡ Setup Instructions
### 1. **Clone the repository**
```bash
git clone https://github.com/MayankGhatawal/UserManagement.git
cd UserManagement-master
```
### 2. **Install dependencies**
```bash
npm install
```
### 3. **Configure environment variables**
Create a `.env` file in the root directory:
```bash
MONGODB_URI=mongodb://localhost:27017/myDatabase
PORT=8000
```
### 4. **Run the server**
```bash
npm run dev
```
Server will start at `http://localhost:8000`.
---
## 📦 API Usage Examples
### 1. **Create User**
```bash
POST /api/addUser
Content-Type: application/json
{
"name": "Mayank Ghatawal",
"email": "mayank1ghatawal@gmail.com",
"mobile": "1234567890"
}
```
### 2. **Get All Users**
```bash
GET /api/getUsers
```
### 3. **Get User by ID**
```bash
GET /api/getUser/
```
### 4. **Update User**
```bash
PUT /api/updateUser/
Content-Type: application/json
{
"name": "Mayank",
"email": "mayank@gmail.com"
"mobile": "1234567890"
}
```
### 3. **Delete User**
```bash
DELETE /api/deleteUser/
```
---
## 📚 Validation & Error Handling
- Returns `400 Bad Request` for missing or invalid fields.
- Returns `404 Not Found` if the user does not exist.
- Returns `500 Internal Server Error` for unexpected errors.
---
## 🎯 Notes
Focus on:
- Clean and readable code
- Modular structure (routes, controllers, models)
- Proper HTTP status codes
- Validation & error handling