0% found this document useful (0 votes)
61 views

Mern Top 50

Vo

Uploaded by

Manav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Mern Top 50

Vo

Uploaded by

Manav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MERN STACK QUESTIONS & ANSWERS

MongoDB (Database)
1. What is MongoDB?

- MongoDB is a NoSQL database that stores data in a flexible, JSON-like format called BSON. It’s
document-oriented and schema-less.

2. What are collections and documents in MongoDB?

- A collection is equivalent to a table in a relational database, and documents are records in that
collection, stored in JSON format.

3. What is a replica set in MongoDB?

- A replica set is a group of MongoDB servers that maintain the same data, providing high
availability and redundancy.

4. What is sharding in MongoDB?

- Sharding is a method for distributing data across multiple servers to scale horizontally and
manage large datasets efficiently.

5. Explain indexing in MongoDB.

- Indexing improves query performance by creating a data structure that enhances the speed of
data retrieval operations.

6. What is Mongoose and why is it used?

- Mongoose is an ODM (Object Data Modeling) library for MongoDB and Node.js, used to manage
relationships between data and provide schema validation.

7. What are the advantages of using NoSQL databases like MongoDB?

- They offer scalability, flexibility in schema design, better handling of large volumes of unstructured
data, and are suitable for distributed data storage.

8. How do you implement pagination in MongoDB?

- Pagination can be implemented using the `skip()` and `limit()` methods in a query.

9. What are the different types of relationships in MongoDB?


MERN STACK QUESTIONS & ANSWERS
- One-to-One, One-to-Many, and Many-to-Many.

10. What are Aggregation Pipelines in MongoDB?

- A framework for data aggregation, allowing data transformation and analysis through a series of
stages (e.g., `$match`, `$group`).

Express.js (Backend Framework)


11. What is Express.js?

- Express.js is a minimal and flexible Node.js web application framework that provides robust
features for building web applications.

12. What is middleware in Express.js?

- Middleware functions have access to the request object, response object, and the `next()`
function in an Express app’s request-response cycle.

13. How do you handle errors in Express.js?

- Use custom error-handling middleware by defining a function with `(err, req, res, next)`.

14. What is routing in Express.js?

- Routing is determining how an application responds to client requests for a specific URL path and
HTTP method.

15. How can you serve static files in Express.js?

- Use `express.static()` middleware to serve static assets like images, CSS, and JS files.

16. How do you secure an Express.js application?

- By using middleware like `helmet`, enabling HTTPS, validating inputs, and setting up proper
authentication and authorization.

17. What is CORS and how do you enable it in an Express.js app?

- CORS (Cross-Origin Resource Sharing) allows controlled access to resources from other domains.
It can be enabled using the `cors` middleware.
MERN STACK QUESTIONS & ANSWERS
18. How do you create a RESTful API using Express.js?

- By defining routes for CRUD operations using HTTP methods like `GET`, `POST`, `PUT`, and
`DELETE`.

19. What is `express.json()` middleware used for?

- It parses incoming JSON payloads and makes them available under `req.body`.

20. What is the role of body-parser in Express.js?

- `body-parser` is middleware used to parse incoming request bodies, now included as


`express.json()` and `express.urlencoded()`.

React.js (Frontend Framework)


21. What is React.js?

- React.js is an open-source front-end library used for building UI components, maintained by


Facebook.

22. What is JSX?

- JSX stands for JavaScript XML, a syntax extension that allows mixing HTML with JavaScript.

23. What are props in React?

- Props are inputs passed to components to make them reusable and are read-only.

24. What is a state in React?

- State is an object that holds component-specific data that may change over time.

25. What are hooks in React?

- Hooks allow functional components to use React features like state (`useState`) and lifecycle
(`useEffect`).

26. What is the Virtual DOM and how does it work?

- The Virtual DOM is an in-memory representation of the real DOM that allows React to perform
efficient updates by comparing it with the real DOM and applying minimal changes.
MERN STACK QUESTIONS & ANSWERS

27. What is `useEffect` and how does it work?

- `useEffect` is a hook that allows you to perform side effects in function components, such as data
fetching or directly interacting with the DOM.

28. What is the difference between controlled and uncontrolled components in React?

- Controlled components are controlled by React state, while uncontrolled components maintain
their own state.

29. What is the `Context API`?

- A feature that enables sharing state across multiple components without passing props manually
at every level.

30. What is the purpose of `useRef` in React?

- `useRef` is a hook that returns a mutable ref object whose `.current` property can be used to
access or modify a DOM element directly.

31. What are React Portals?

- A feature that allows rendering a component’s children into a DOM node outside the parent
hierarchy.

32. Explain HOC (Higher-Order Component).

- A HOC is a function that takes a component and returns a new component, used to enhance
component functionality.

33. What is `useMemo`?

- `useMemo` is a hook that memorizes the result of a computation to optimize performance and
prevent unnecessary recalculations.

34. How do you optimize performance in a React app?

- By using techniques like memoization, lazy loading, code-splitting, and avoiding unnecessary re-
renders.

35. What is server-side rendering (SSR) in React?


MERN STACK QUESTIONS & ANSWERS
- SSR is a technique where React components are rendered on the server and sent to the client as
pre-rendered HTML for faster load times and SEO benefits.

Node.js (Server Environment)


36. What is Node.js?

- Node.js is a JavaScript runtime that allows JavaScript code to be run on the server side, using
Chrome’s V8 engine.

37. What is the event loop in Node.js?

- A mechanism that handles all asynchronous operations and callbacks in Node.js, ensuring non-
blocking I/O.

38. What is `npm` and its purpose?

- `npm` is Node Package Manager, used to install, update, and manage dependencies in a Node.js
project.

39. What is `require()` in Node.js?

- `require()` is used to include external modules or files in Node.js.

40. What is the difference between `require` and `import` in Node.js?

- `require` is from CommonJS and is synchronous, while `import` is ES6 syntax that supports `tree-
shaking` and is asynchronous.

41. Explain the concept of Node.js streams.

- Streams are a way to read or write data continuously and asynchronously in Node.js, used for
processing large data sets efficiently.

42. What is event delegation in Node.js?

- A pattern where a single event listener is set for a parent element to handle events triggered by
its children, improving performance.

43. What is the `cluster` module in Node.js?


MERN STACK QUESTIONS & ANSWERS
- The `cluster` module allows Node.js to create child processes (workers) that share the same
server port to handle concurrent requests and scale an application.

44. What is Nodemon?

- Nodemon is a tool that automatically restarts a Node.js application when file changes are
detected, improving development workflow.

45. What are middleware functions in Node.js?

- Middleware functions process requests between the time they are received and sent as
responses, and are essential in Express.js for request handling.

46. Explain JWT (JSON Web Token).

- JWT is a compact, URL-safe means of representing claims between two parties. It is used for
securely transmitting information as a JSON object and is commonly used in authentication.

47. What is `dotenv` and why is it used?

- `dotenv` is a module that loads environment variables from a `.env` file into `process.env` for
better configuration management.

48. What is the difference between synchronous and asynchronous programming in Node.js?

- Synchronous programming blocks the execution until the task is completed, while asynchronous
programming allows the execution to continue while waiting for the task to finish.

49. How do you handle file uploads in Node.js?

- File uploads can be handled using middleware like `multer` to parse `multipart/form-data`.

50. How do you deploy a MERN stack application?

- Deploy using cloud services such as Heroku, Vercel, or AWS, setting up the client and server to
run in a production environment.

You might also like