Complete MERN Stack Interview Questions and Answers
General Questions
Q: What is the MERN stack?
A: MERN stands for MongoDB, Express.js, React.js, and Node.js.
Q: How does the MERN stack work together?
A: React for UI, Express and Node for backend, MongoDB for database.
Q: What are the advantages of MERN stack?
A: Full JavaScript stack, fast development, great community support.
MongoDB Questions
Q: What is MongoDB?
A: A NoSQL, document-based database.
Q: What is Mongoose?
A: An ODM (Object Data Modeling) library for MongoDB and Node.js.
Q: How to define a schema in Mongoose?
A: Using mongoose.Schema and mongoose.model.
Q: What are MongoDB Aggregations?
A: Operations that process data records and return computed results.
Express.js Questions
Q: What is Express.js?
A: A Node.js framework for building web applications and APIs.
Q: What is middleware in Express?
A: Functions that process requests before they reach routes.
Q: How do you handle errors in Express?
A: Using error-handling middleware.
Q: How do you define routes in Express?
A: Using app.get(), app.post(), etc.
React.js Questions
Q: What is React?
A: A library for building user interfaces.
Q: What are components in React?
A: Reusable UI pieces: functional and class-based.
Q: What are hooks?
A: Functions like useState, useEffect for managing state and side effects.
Q: What is JSX?
A: A syntax extension for JavaScript that looks like HTML.
Q: What is the virtual DOM?
A: A lightweight copy of the real DOM that React uses for performance.
Q: How to manage state in React?
A: Using useState, useReducer, or libraries like Redux.
Node.js Questions
Q: What is Node.js?
A: A JavaScript runtime to run code outside the browser.
Q: What is the event loop?
A: It handles asynchronous operations in Node.js.
Q: What are streams in Node.js?
A: Objects for reading/writing data piece-by-piece.
Q: How to handle async code?
A: Using callbacks, promises, and async/await.
Full-Stack Integration Questions
Q: How to connect React with Express?
A: Using axios or fetch to make API calls.
Q: How to connect Express with MongoDB?
A: Using mongoose.connect().
Q: What is CORS and how to handle it?
A: Cross-Origin Resource Sharing, handled with cors middleware.
Q: How do you manage environment variables?
A: Using .env file and dotenv package.
Authentication & Security Questions
Q: What is JWT?
A: JSON Web Token used for authentication.
Q: How to implement JWT authentication?
A: Generate token on login, verify in protected routes.
Q: What is OAuth?
A: An open standard for access delegation.
Q: How to secure Express apps?
A: Use HTTPS, helmet, rate limiter, input validation.
Deployment & DevOps Questions
Q: How to deploy MERN stack?
A: Frontend on Netlify/Vercel, backend on Heroku/Render, MongoDB on Atlas.
Q: What is CI/CD?
A: Continuous Integration/Continuous Deployment for automated testing and deployment.
Q: How to use PM2?
A: PM2 is a process manager to keep Node.js apps alive.
Q: What is Docker?
A: A container platform used to package applications.
Advanced Topics Questions
Q: What is Redux?
A: A state management library.
Q: What is SSR in React?
A: Server-Side Rendering to improve SEO and performance.
Q: What is Next.js?
A: A React framework for SSR and static site generation.
Q: What are design patterns in MERN apps?
A: MVC, modular structure, and service layers.
Q: What are common performance optimizations?
A: Lazy loading, memoization, code splitting.