Welcome to the User Management Service, a robust web service designed to handle user-related operations. This service is part of a broader Service-Oriented Architecture (SOA) project. Built with modern libraries and best practices, it ensures security, scalability, and excellent performance.
- User Registration: Secure sign-ups with bcrypt for password hashing.
- CRUD Operations: Manage user information with Create, Read, Update, and Delete operations.
- Comprehensive API Documentation: Integrated Swagger documentation for easy API exploration.
- Logging & Testing: Winston for logging, Jest for testing, and Supertest for API testing.
- In-Memory Database for Testing: Utilizes
mongodb-memory-server
to provide a lightweight, fast, in-memory MongoDB instance for testing. - Security: Helmet, rate limiting, and bcrypt ensure the service is protected from common vulnerabilities.
- Node.js: The runtime environment.
- Express.js: Web framework for building REST APIs.
- MongoDB + Mongoose: Database and ODM for persisting user data.
- Swagger: Automatically generated API documentation.
- Libraries in Use:
- Winston: Comprehensive logging.
- dotenv: Manage environment variables.
- Morgan: HTTP request logger.
- Helmet: Adds extra security headers.
- Compression: Reduces response size.
- body-parser: Parses incoming request bodies.
- bcrypt: Secure password hashing.
- express-async-handler: Simplifies handling async operations.
- express-rate-limit: Limits request rates to prevent abuse.
- Joi: Input validation.
- Swagger-jsdoc & swagger-ui-express: Generate and display API documentation.
- nodemon: Automatic restarts during development.
- Jest & Supertest: For testing and validating endpoints.
- mongodb-memory-server: In-memory MongoDB for testing without a real database.
This table provides a concise overview of the available endpoints, their respective HTTP methods, descriptions, and expected status codes.
Method | Endpoint | Description | Status Code |
---|---|---|---|
GET |
/api/users |
Fetch all registered users | 200 OK |
POST |
/api/users/register |
Register a new user | 201 Created |
PUT |
/api/users/:id |
Update user details by ID | 200 OK |
DELETE |
/api/users/:id |
Delete a user by ID | 200 OK |
Access the complete, interactive API documentation via Swagger at:
http://localhost:3000/api-docs
Before running the project, set up a .env
file at the root of the project with the following variables:
PORT=3000
MONGODB_URI=<Your MongoDB URI>
NODE_ENV=<development | production | test>
Ensure you have the following installed:
- Clone the repository:
git clone https://github.com/Yassinekrn/user-management-service.git
- Navigate to the project directory:
cd user-management-service
- Install dependencies:
npm install
- Run the server in development mode:
npm run devstart
The service will be available at http://localhost:<PORT>
*.
*Defaults to 5000 if you do not setup dotenv.
Testing is an integral part of the service. We use Jest for unit and integration tests, with Supertest to test the API endpoints.
To run tests:
npm test
This project uses mongodb-memory-server
for testing purposes, which spins up an in-memory MongoDB instance. This allows for fast and isolated tests without affecting the production database.
- Password Hashing: All passwords are securely hashed using bcrypt.
- Rate Limiting: Protects against brute-force attacks.
- Helmet: Adds security headers to safeguard against common web vulnerabilities.
- Input Validation: Ensures all incoming data is properly validated using Joi.
Contributions are welcome! Please follow these steps:
- Fork the project.
- Create your feature branch (
git checkout -b feature/YourFeature
). - Commit your changes (
git commit -m 'Add YourFeature'
). - Push to the branch (
git push origin feature/YourFeature
). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
Maintained by Yassine Krichen