Advanced MERN Stack Interview Questions and Answers
Q: What is JWT and how is it used in MERN applications?
A: JWT (JSON Web Token) is used for authentication. It contains a payload (user data) and is
signed using a secret. It is sent in the Authorization header and verified by the server.
Q: How do you implement authentication with JWT in Express?
A: Generate a token with jsonwebtoken library after login, send it to the client, and verify it on
protected routes using middleware.
Q: What is the difference between authentication and authorization?
A: Authentication verifies user identity, while authorization checks user permissions.
Q: How do you deploy a MERN application?
A: Frontend can be deployed on Netlify or Vercel, backend on Heroku or Render, and database
(MongoDB) on Atlas.
Q: How do you optimize performance in a React application?
A: Use memoization ([Link], useMemo), code splitting, lazy loading, and avoid unnecessary
re-renders.
Q: What are some common security practices in MERN stack apps?
A: Use HTTPS, sanitize inputs, implement rate limiting, use helmet, and validate JWT tokens.
Q: How do you handle file uploads in MERN?
A: Use multer middleware in Express and FormData in React.
Q: What is Redux and when should you use it in MERN?
A: Redux is a state management library useful when multiple components need to share and
manage state.
Q: How do you handle errors globally in Express?
A: Use custom error-handling middleware at the end of route declarations.
Q: How can you secure API routes in Express?
A: Use authentication middleware, check JWT tokens, and restrict access based on roles.