A RESTful API built with Node.js, Express, and MongoDB for managing users and admin functionality. This project was developed as part of a Backend Developer Internship assignment.
Create a RESTful API for User Management System that demonstrates understanding of backend development principles and problem-solving skills.
-
User Registration
- Users can create account with name, email, password, phone number
- Input validation for email format and password length
- Prevention of duplicate email registrations
-
User Authentication
- Login functionality using email and password
- Proper error handling for invalid credentials
-
Profile Management
- Users can view their details (name, email, phone number)
- Users can update their profile information
-
Account Deactivation
- Users can deactivate their accounts
- Implemented using soft delete approach (maintaining data but preventing login)
-
Super Admin Features
- Special access to view all users' details
- Secure admin authentication system
- Uses same database model with role-based access
- Node.js
- Express.js
- MongoDB
- JWT for Authentication
- bcrypt for Password Hashing
- Clone the repository
git clone https://github.com/vishwa-glitch/User-management
cd src
- Install dependencies
npm install
- Set up environment variables in
.env
PORT=3000
MONGODB_URI=mongodb://localhost:27017/user-management
JWT_SECRET=your_jwt_secret_key
- Start the server
node server.js
POST /api/auth/register
{
"name": "Test User",
"email": "user@test.com",
"password": "password123",
"phoneNumber": "1234567890"
}
POST /api/auth/login
{
"email": "user@test.com",
"password": "password123"
}
GET /api/users/me
PATCH /api/users/update-me
DELETE /api/users/deactivate
GET /api/admin/users
GET /api/admin/dashboard
PATCH /api/admin/users/:userId/status
-
Account Deactivation Strategy
- Implemented soft delete using isActive flag
- Preserves user data while preventing access
- Better for data analysis and recovery
-
Super Admin Implementation
- Single user model with role-based access
- Admin created through setup script
- Secure and maintainable approach
- Email format validation
- Password minimum length (8 characters)
- Phone number format validation
- Unique email constraint
- Required field validation
- Graceful error messages
- Proper HTTP status codes
- Validation error responses
- Authentication error handling
Import the provided Postman collection to test all endpoints:
- Register new users
- Test authentication
- Test protected routes
- Test admin features
- Password hashing
- JWT-based authentication
- Role-based authorization
- Input sanitization
- Protected routes middleware
user-management-system/
├── src/
│ ├── config/
│ ├── controllers/
│ ├── middleware/
│ ├── models/
│ ├── routes/
│ ├── utils/
│ ├── app.js
│ └── server.js
├── .env
└── package.json