MERN Stack Interview Questions & Answers
All 200 unique questions in one place — 60 easy, 98 medium, 42 hard — grouped by topic.
Practise by topic
Practise the way your interview works
Explain hoisting in JavaScript with an example.
Show answer
What is a closure and where is it useful?
Show answer
What is the difference between == and === in JavaScript?
Show answer
How do arrow functions differ from regular functions?
Show answer
What is a Promise and what are its states?
Show answer
Explain destructuring, the spread operator and rest parameters.
Show answer
A for loop using var with setTimeout inside prints 3, 3, 3 instead of 0, 1, 2. Why, and how do you fix it?
Show answer
Tell me about a time you had to learn a new JavaScript concept quickly to finish a task.
Show answer
How does the JavaScript event loop work with microtasks and macrotasks?
Show answer
How does async/await improve on Promise chains, and how do you handle errors with it?
Show answer
What is the difference between a shallow copy and a deep copy?
Show answer
Compare Promise.all, Promise.allSettled, Promise.race and Promise.any.
Show answer
What is the output order of console.log('A'), setTimeout(() => console.log('B'), 0), Promise.resolve().then(() => console.log('C')) and console.log('D')?
Show answer
A search box fires an API request on every keystroke and overloads the backend. How would you solve it?
Show answer
How do you debug a JavaScript bug that a user reports but you cannot reproduce locally?
Show answer
Write a debounce function in JavaScript.
Show answer
Write a function to flatten a nested array without using Array.prototype.flat.
Show answer
Group an array of order objects by their status using reduce.
Show answer
How does prototypal inheritance work, and how does class syntax relate to it?
Show answer
You need to call an external API 500 times but it allows only 5 concurrent requests. How would you implement this?
Show answer
A single-page app gets slower the longer a user keeps it open. What JavaScript memory leaks would you check for?
Show answer
Implement your own version of Promise.all.
Show answer
Write a deep clone function that handles nested objects, arrays and dates.
Show answer
Write an async helper that retries a failing call with exponential backoff.
Show answer
What is Node.js and how does it handle many requests on a single thread?
Show answer
What is the difference between CommonJS and ES modules in Node.js?
Show answer
What is a Buffer in Node.js?
Show answer
What is the EventEmitter class and where is it used?
Show answer
What is the difference between package.json and package-lock.json, and what do ^ and ~ mean?
Show answer
How do you manage configuration and secrets differently for development and production in Node.js?
Show answer
Create a basic HTTP server in Node.js without Express that returns JSON.
Show answer
Read a JSON file and write an updated version using fs/promises and async/await.
Show answer
Show how to create and use a custom EventEmitter.
Show answer
How do you set up npm scripts for development and production in a Node.js API?
Show answer
What is the difference between process.nextTick, setImmediate and setTimeout(fn, 0)?
Show answer
What are streams in Node.js and what types exist?
Show answer
Your API becomes unresponsive whenever a user uploads an image for resizing. What is happening and how do you fix it?
Show answer
Your script crashes with out of memory while reading a 5 GB log file. How would you rewrite it?
Show answer
How do you implement graceful shutdown for a Node.js API during deployments?
Show answer
Your Node.js API runs on an 8-core server but CPU monitoring shows only one core busy. What do you do?
Show answer
Compress a large file with gzip using streams in Node.js.
Show answer
How do you add a timeout to a fetch call in Node.js?
Show answer
Describe a production issue you handled in a Node.js service.
Show answer
How do you plan a Node.js major version upgrade for a project your team maintains?
Show answer
Explain the phases of the Node.js event loop.
Show answer
What is libuv and which operations use the Node.js thread pool?
Show answer
Compare worker_threads, cluster and child_process in Node.js.
Show answer
How should errors be handled in a Node.js application?
Show answer
Memory usage of a production Node.js service keeps rising until it restarts. How do you investigate?
Show answer
What is Express.js and what is middleware?
Show answer
Why does the order of middleware matter in Express?
Show answer
What is the difference between app.use, app.get and express.Router?
Show answer
What is the difference between req.params, req.query and req.body?
Show answer
Which HTTP status codes should a REST API commonly return?
Show answer
The React app works locally but shows CORS errors after deployment. What would you check?
Show answer
Write an Express router with CRUD routes for a products resource.
Show answer
How would you explain a technical decision, such as choosing REST over GraphQL, to a non-technical manager?
Show answer
How does error-handling middleware work in Express, and what changed in Express 5?
Show answer
What are the core principles of a RESTful API, and which HTTP methods are idempotent?
Show answer
What is CORS and how do you configure it in an Express API?
Show answer
What strategies can you use to version a REST API?
Show answer
What are the important changes in Express 5 compared to Express 4?
Show answer
Users must upload files up to 200 MB. How would you handle this in a MERN application?
Show answer
How do you protect a public Express API from abuse and brute-force traffic?
Show answer
Your API has 40 routes and each returns errors in a different format. How would you standardise this?
Show answer
Write Express middleware that logs method, URL, status code and response time.
Show answer
Write a reusable validation middleware for Express using zod.
Show answer
Write an asyncHandler wrapper for Express 4 route handlers.
Show answer
Write a central error-handling middleware with a custom AppError class.
Show answer
How would you structure the folders of a production Express API?
Show answer
Tell me about a time you disagreed with a teammate about an API design decision.
Show answer
Compare offset-based and cursor-based pagination for an API.
Show answer
Your Express API slows down badly during peak traffic. How do you find and fix the bottleneck?
Show answer
Design a payment endpoint so that client retries never charge a user twice.
Show answer
What is MongoDB and how is it different from a relational database?
Show answer
What are BSON and ObjectId in MongoDB?
Show answer
What are a Mongoose schema and model, and how does validation work?
Show answer
A client wants deleted records to be recoverable. How would you implement soft delete with Mongoose?
Show answer
Write basic CRUD commands in mongosh for a users collection.
Show answer
Write a Mongoose schema for a user with validation and timestamps.
Show answer
Implement page-based pagination for a products API with Mongoose.
Show answer
When should you embed documents and when should you reference them in MongoDB?
Show answer
What is the aggregation pipeline and what are its common stages?
Show answer
What are Mongoose middleware hooks and give a common use case.
Show answer
What does lean() do in Mongoose and when should you use it?
Show answer
A MongoDB query on an orders collection takes 3 seconds. How do you diagnose and fix it?
Show answer
Duplicate user accounts with the same email are being created even though the code checks for an existing email first. Why, and how do you fix it?
Show answer
The business wants total sales per category for the last 30 days. How would you build it in MongoDB?
Show answer
Write an aggregation that counts orders and sums revenue per status.
Show answer
Create a compound index for a user's order history query and verify it is used.
Show answer
Show the use of $push, $addToSet, $inc and $pull update operators.
Show answer
Tell me about a time you improved the performance of a slow database-driven feature.
Show answer
Describe a mistake you made with data and how you handled it.
Show answer
Explain indexes in MongoDB, compound indexes and the ESR rule.
Show answer
What is the difference between Mongoose populate and the $lookup aggregation stage?
Show answer
How do transactions work in MongoDB and when do you need them?
Show answer
What are replica sets and sharding in MongoDB, and how do you choose a shard key?
Show answer
You stored all comments inside each blog post document and some posts are now very large. How would you redesign it?
Show answer
You need to rename a field and change its type across 20 million documents in production. How do you do it safely?
Show answer
What is React and how does the virtual DOM help performance?
Show answer
What is JSX and how is it converted into JavaScript?
Show answer
What is the difference between props and state in React?
Show answer
Why are functional components preferred over class components today?
Show answer
Why does React need keys in lists, and why is using the array index risky?
Show answer
What does lifting state up mean in React?
Show answer
What are the common ways to render content conditionally in React?
Show answer
Two sibling components need to share data. How do you handle it?
Show answer
How should a component display data loaded from an API in a user-friendly way?
Show answer
Write a counter component using useState.
Show answer
Write a controlled login form that submits to an API.
Show answer
Tell me about a time you received critical feedback on your UI code and how you responded.
Show answer
Why do you want to work as a MERN stack developer?
Show answer
What is the difference between controlled and uncontrolled components?
Show answer
How does routing work in a React single-page app using React Router?
Show answer
How do class component lifecycle methods map to hooks?
Show answer
What are React fragments and portals?
Show answer
Every time a user types in an input inside a list item, the input loses focus. What could be the cause?
Show answer
You are building a registration form with ten fields and validation. How do you manage its state?
Show answer
How do you protect certain routes in React so that only logged-in users can access them?
Show answer
A component calls setState inside useEffect and the app goes into an infinite render loop. Why?
Show answer
Fetch a list of users from an API inside useEffect with proper cleanup.
Show answer
Build a simple todo list in React with add and delete.
Show answer
Set up React Router with a layout, a list page and a detail page using useParams.
Show answer
Tell me about a time you had to deliver a frontend feature under a tight deadline.
Show answer
What are the main uses of useRef?
Show answer
How does the useEffect dependency array work and why is cleanup important?
Show answer
What is the difference between useMemo and useCallback?
Show answer
What does React.memo do and when is it useful?
Show answer
What is the Context API and when should you avoid it?
Show answer
When should you use useReducer instead of useState?
Show answer
What is a custom hook and what rules must hooks follow?
Show answer
Explain the core ideas of Redux Toolkit.
Show answer
How do you implement code splitting in a React app?
Show answer
Props are being passed through five levels of components that do not use them. How would you refactor?
Show answer
An error in one dashboard widget crashes the entire React page. How do you contain it?
Show answer
Write a reusable useFetch custom hook.
Show answer
Write a useDebounce hook and use it for a search input.
Show answer
Create an AuthContext with a provider and a custom hook.
Show answer
Implement a shopping cart with useReducer.
Show answer
How have you helped junior developers improve their React skills?
Show answer
What is the difference between server state and client state, and why use a library like TanStack Query?
Show answer
What are the key new features in React 19?
Show answer
Explain CSR, SSR, hydration and React Server Components.
Show answer
Typing in a filter box over a list of 10,000 rows feels laggy. How do you fix it?
Show answer
A setInterval inside useEffect always logs the initial count value instead of the updated one. Why, and how do you fix it?
Show answer
Your React production bundle is 3 MB and the first load is slow on mobile. What steps do you take?
Show answer
Fast typing in a search box sometimes shows results for an older query. What causes this and how do you fix it?
Show answer
Write a Redux Toolkit slice that fetches products with createAsyncThunk.
Show answer
Tell me about a time you led a technical migration in a frontend codebase.
Show answer
What is the difference between authentication and authorization?
Show answer
What is a JWT and what are its three parts?
Show answer
How should passwords be stored, and why use bcrypt?
Show answer
What does the helmet middleware do in Express?
Show answer
Write a register endpoint that hashes the password with bcrypt.
Show answer
Why do applications use both access tokens and refresh tokens?
Show answer
Should you store a JWT in localStorage or in an httpOnly cookie?
Show answer
How does React protect against XSS and where can XSS still happen?
Show answer
What is NoSQL injection and how do you prevent it in a MongoDB app?
Show answer
Your app needs user, editor and admin roles with different permissions. How would you implement it?
Show answer
A developer accidentally pushed the .env file with the MongoDB password and JWT secret to a public repository. What do you do?
Show answer
Attackers are trying thousands of passwords on your login endpoint. How do you defend it?
Show answer
Design a secure forgot-password flow for a MERN application.
Show answer
Write an Express middleware that verifies a JWT from the Authorization header.
Show answer
Set a refresh token in a secure httpOnly cookie after login.
Show answer
Write a role-based authorization middleware for Express.
Show answer
What practical steps do you take to sanitise and validate input in an Express and MongoDB API?
Show answer
Tell me about a time you found and fixed a security issue in an application.
Show answer
Compare session-based authentication with JWT-based authentication.
Show answer
What is CSRF and how do SameSite cookies help prevent it?
Show answer
How does Sign in with Google work using OAuth 2.0 and OpenID Connect?
Show answer
When a user logs out or changes password, how do you make sure their existing JWTs stop working?
Show answer
Users can upload profile pictures and documents. What security measures do you put in place?
Show answer
Write an Axios interceptor in React that refreshes the access token on a 401 response.
Show answer
How do you handle pressure to ship quickly when you think a feature is not secure yet?
Show answer
What is the difference between unit, integration and end-to-end tests in a MERN app?
Show answer
What are Jest and Vitest, and what is the philosophy of React Testing Library?
Show answer
How does Supertest help test Express APIs?
Show answer
How do environment variables work in a Vite React app compared to a Node.js backend?
Show answer
Your MERN app works on your laptop but crashes after deployment to a server. How do you troubleshoot?
Show answer
After deploying a React app, refreshing on a page like /dashboard shows a 404 error. Why, and how do you fix it?
Show answer
Write a unit test for a function that calculates a cart total.
Show answer
What is mocking and when should you mock in tests?
Show answer
How is Docker used in a MERN project?
Show answer
What does a CI/CD pipeline for a MERN application usually include?
Show answer
What is PM2 and why is it used to run Node.js in production?
Show answer
How is Nginx used in front of a MERN application?
Show answer
Some tests pass locally but fail randomly in CI. How do you handle flaky tests?
Show answer
Write a React Testing Library test for a counter button.
Show answer
Write a Supertest integration test for a POST /api/users endpoint.
Show answer
Write a production Dockerfile for a Node.js Express API.
Show answer
Write a docker-compose file to run a MERN app locally.
Show answer
Walk me through a MERN project you built, end to end.
Show answer
Tell me about a deployment that went wrong and what you learned.
Show answer
What logging and monitoring should a production MERN app have?
Show answer
How would you use Redis caching in a MERN backend and what are the pitfalls?
Show answer
Your MERN product is expected to grow from 1,000 to 1 lakh daily users. How would you prepare the architecture?
Show answer
How would you achieve zero-downtime deployments for an Express API?
Show answer
Your chat feature uses Socket.IO and must now run on multiple Node instances. What changes are needed?
Show answer
Write a GitHub Actions workflow that tests and builds a MERN project on every pull request.
Show answer
Frequently asked questions
What jobs can I get after learning the MERN stack?
You can apply for roles such as MERN Stack Developer, Full Stack JavaScript Developer, React Developer, Node.js Backend Developer and Frontend Engineer. Startups, product companies and IT service firms across India hire for these roles, especially in Bengaluru, Pune, Hyderabad, Noida, Gurugram and Chennai. Many remote roles for global clients also use MERN. With experience, you can grow into senior full stack, tech lead or solution architect positions.
Who is eligible to learn the MERN stack?
Anyone comfortable using a computer and willing to practise daily can learn MERN. It suits B.Tech, BCA, MCA, B.Sc and diploma students, freshers from any stream, and working professionals moving into development from testing, support or non-IT roles. No prior coding experience is strictly required, but basic logical thinking helps. The course starts with HTML, CSS and JavaScript before moving to React, Node.js and MongoDB.
How long does it take to become job-ready in MERN?
With focused study of two to three hours a day, most learners become job-ready in about five to six months. The first two months go into web basics, JavaScript and React, the next two into Node.js, Express and MongoDB, and the final phase into authentication, testing, deployment and projects. Building two or three complete projects and practising interview questions regularly matters more than the exact duration.
Do I need a certification to get a MERN developer job?
Certifications help your resume pass initial screening and show structured learning, but recruiters mainly judge MERN candidates by their projects, GitHub profile and interview performance. A course completion certificate plus optional credentials such as the MongoDB Associate Developer certification can add value. Focus on deployed projects with clean code, a clear README and live links, because interviewers often ask you to explain and extend them.
Is MERN better than Java full stack or MEAN for a fresher?
Each has strong demand. MERN uses JavaScript end to end and React, which is the most popular frontend library, so it suits startups and product companies that move fast. Java full stack is widely used in banks and large enterprises. MEAN uses Angular, popular in some enterprise projects. For a fresher, MERN offers a quicker learning curve and a large number of openings, and the skills transfer well to Next.js and TypeScript.
What projects should I build to get hired as a MERN developer?
Build two or three complete, deployed projects rather than many small demos. Good choices are an e-commerce store with cart, orders and admin panel, a job portal with recruiter and candidate roles, a real-time chat app using Socket.IO, or a booking system with payments in test mode. Include authentication, validation, pagination, file uploads, tests and a CI pipeline, and be ready to explain every design decision.