This is a basic backend application built with Node.js and Express.js. It simulates user registration, login, and profile management using mock models (in-memory arrays or JSON files) as a simulated database. The project demonstrates key functionalities such as authentication, rate limiting, logging, and proper separation of concerns within the structure of a Node.js application.
Project/
├── app.js
├── routes/
│ └── user.js
├── controllers/
│ └── userController.js
├── models/
│ └── userModel.js
├── middleware/
│ └── authMiddleware.js
│ └── loggingMiddleware.js
│ └── rateLimitMiddleware.js
├── utils/
│ └── responses.js
└── data/
└── users.jsonnpm install express body-parser jsonwebtoken joi dotenv express-rate-limit nodemonJWT_SECRET=your_jwt_secret_key
PORT = 5001 (depends on you)npm startnpm run devhttp://localhost:<port>/register{
"username":"momohirai",
"password":"momohirai123",
"email":"momohirai@gmail.com"
}http://localhost:<port>/login{
"username":"jihyopark",
"password":"jihyopark123"
}http://localhost:<port>/profileHeader:
Authorization: Bearer <your-jwt-token>http://localhost:<port>/allUsers- User Registration: Allows new users to register by providing a username, password, and email.
- User Login: Authenticates users and provides a JWT token for secure access to protected routes.
- Profile Management: Retrieves user profile details for authenticated users.
- Input Validation: Uses Joi for validating user input in registration and login routes.
- Token-based Authentication: Protects the profile route with JWT-based authentication.
- Logging Middleware: Logs details of each request, including method, route, and timestamp.
- Rate Limiting (Optional): Implement rate limiting for API requests.