This project is a user authentication system built with Express.js, MongoDB, Redis, and PM2. It supports user registration, login, and user search, with Redis caching for optimized query performance and PM2 for process management.
- User Registration: Store user credentials securely with bcrypt.
- User Login: Authenticate users with JWT.
- Search User: Find users by email or username.
- Redis Caching: Cache database queries to improve performance.
- PM2 Support: Process management for better scalability and monitoring.
- Backend: Express.js (Node.js)
- Database: MongoDB with Mongoose
- Authentication: JWT & bcrypt
- Caching: Redis
- Process Management: PM2
-
Clone the repository:
git clone [email protected]:SagarKapoorin/User.git cd User
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.envfile and add the following:MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key PORT=3000 redis_Url=redis://127.0.0.1:6379
-
Start Redis server (if not running):
redis-server
-
Run the server:
npm start
-
To run with PM2:
pm2 start src/index.js -i max --no-daemon
- POST
/api/auth/register - Body:
{ "username": "john_doe", "email": "[email protected]", "password": "securepassword", "fullName": "John Doe", "gender": "Male", "dateOfBirth": "1990-09-22", "country": "USA" }
- POST
/api/auth/login - Body:
{ "email": "[email protected]", "password": "securepassword" }
- GET
/api/users/[email protected]
To keep the server running in the background:
npm install -g pm2
npm run startTo stop the server:
npm run stopThe source code is located in the src folder.
Made by Sagar Kapoor
This project is open-source and available under the MIT License.