MERN Stack Interview Questions and Answers
Q: What is the MERN stack?
A: MERN stands for MongoDB, Express.js, React.js, and Node.js. It's a full-stack JavaScript
solution.
Q: How does the MERN stack work together?
A: React handles the frontend, Express.js and Node.js manage the backend, MongoDB is used for
the database.
Q: What is MongoDB and why is it used in MERN?
A: MongoDB is a NoSQL, document-oriented database. It stores data in BSON (JSON-like) format.
Q: How do you create and retrieve data in MongoDB?
A: Use insertOne(), insertMany(), find(), and findOne() methods.
Q: What are indexes in MongoDB?
A: Indexes improve query performance. Created using createIndex().
Q: What is Express.js?
A: Express is a minimal Node.js web framework used to build APIs and web applications.
Q: How do you create an API in Express?
A: Use app.get() or app.post() methods to define routes.
Q: What is middleware in Express?
A: Functions that handle requests before reaching the route handler.
Q: What is React and why is it used in MERN?
A: React is a library for building user interfaces using reusable components.
Q: What are hooks in React?
A: Functions like useState and useEffect used in functional components.
Q: Explain the virtual DOM.
A: A lightweight representation of the real DOM used by React for efficient updates.
Q: What is Node.js?
A: Node.js is a JavaScript runtime that executes code outside the browser.
Q: What is the event loop in Node.js?
A: It handles async operations like I/O without blocking the main thread.
Q: How do you handle async code in Node.js?
A: Using callbacks, promises, or async/await.
Q: How do you connect React with Express?
A: Use fetch or axios in React to make HTTP requests to Express routes.
Q: How do you connect Express with MongoDB?
A: Use Mongoose or MongoDB native driver to connect.
Q: What is CORS and how do you handle it?
A: CORS allows cross-origin requests, handled with the cors package in Express.