Node.js Advanced (Coding)

 60 Minutes
 2 Questions

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. Including: Express.js, Rate Limiting (express-rate-limit), JSON Web Tokens (JWT), Backend Authentication and Password Hashing

Example Question:

Develop an authentication system for an Express.js application.
The requirements are as follows:
User Registration:
  • Endpoint: POST /register
  • Data: username, password, and email.
  • Hash passwords before storing them in an in-memory user store.
User Login:
  • Endpoint: POST /login
  • Data: username and password.
  • Upon successful login, provide the user with a JWT set in a cookie.
User Profile:
  • Endpoint: GET /profile
  • Middleware: Protected by JWT verification.
Admin Access:
  • Endpoint: GET /admin
  • Middleware: Protected by both JWT and role-checking middleware. Only users with the role admin should access this.
  • Endpoint: GET /logout
  • 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.