Welcome to the world of Node.js development! This assignment outlines the key features and requirements for your Node.js project. The goal is to create a robust application with user authentication, role-based access control, and secure API endpoints.
-
Signup:
- Collect basic details (email, phone number, name, profile image, password) during the signup process.
- Ensure at least one of the phone number or email is provided during signup.
- Implement encryption for passwords.
-
Login:
- Allow users to log in using email/phone and password.
-
Modify User Details:
- Users can only modify their own name and profile image.
- Phone number and email, once entered, cannot be changed.
-
Delete User:
- Users should have the ability to delete their accounts.
-
Roles:
- Define two roles: Admin and User.
-
Admin Access:
- Admins can view, modify, and delete all user details.
-
User Access:
- Users can only view, modify, and delete their own details.
- Create Admin:
- Create APIs to allow the creation of admin accounts.
-
Authentication:
- Implement an authentication system using JSON Web Tokens (JWT).
-
Password Encryption:
- Use bcrypt to securely encrypt user passwords.
- Profile Image:
- Save profile images integrate with a third-party service Cloudinary.
- Framework:
- Utilize Express.js for API development.
- Database:
- Choosed MongoDB for the database.
- Data Validation:
- Implement thorough data validation to ensure the correctness and integrity of input data.
To run the project, you need to set up the following environment variables. Create a .env
file in the root of your project and add the following variables with your own values:
# .env
MONGO_URI="mongodb+srv:https://your-username:[email protected]/?retryWrites=true&w=majority"
JWT_SECRET="your-jwt-secret-key"
CLOUD_NAME="your-cloudinary-cloud-name"
CLOUD_KEY="your-cloudinary-api-key"
CLOUD_KEY_SECRET="your-cloudinary-api-key-secret"