Node.js Advanced (Coding)
Test Description: Node.js Backend Functionality with Key Libraries
This test focuses on the creation and management of a secure Node.js backend using Express.js, along with several essential middleware and libraries. The primary goal is to assess the server's ability to handle user authentication, rate limiting, and data security.
Express.js, Rate Limiting (express-rate-limit), JSON Web Tokens (JWT), Backend Authentication and Password HashingStart Today
Develop an authentication system for an Express.js application.
The requirements are as follows:
- Hash passwords before storing them in an in-memory user store.
- Upon successful login, provide the user with a JWT set in a cookie.
- Middleware: Protected by JWT verification.
- Middleware: Protected by both JWT and role-checking middleware. Only users with the role
admin should access this.
- Clear the JWT cookie for the logged-in user.
You are expected to use the following libraries to achieve the above requirements:
express: For setting up the server and routes.
jsonwebtoken: For generating and verifying JSON Web Tokens.
bcryptjs: For hashing user passwords.
cookie-parser: For parsing cookies from requests.
Please ensure your solution integrates these libraries and endpoints appropriately.