Mern Top 50
Mern Top 50
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.
- A collection is equivalent to a table in a relational database, and documents are records in that
collection, stored in JSON format.
- A replica set is a group of MongoDB servers that maintain the same data, providing high
availability and redundancy.
- Sharding is a method for distributing data across multiple servers to scale horizontally and
manage large datasets efficiently.
- Indexing improves query performance by creating a data structure that enhances the speed of
data retrieval operations.
- Mongoose is an ODM (Object Data Modeling) library for MongoDB and Node.js, used to manage
relationships between data and provide schema validation.
- They offer scalability, flexibility in schema design, better handling of large volumes of unstructured
data, and are suitable for distributed data storage.
- Pagination can be implemented using the `skip()` and `limit()` methods in a query.
- A framework for data aggregation, allowing data transformation and analysis through a series of
stages (e.g., `$match`, `$group`).
- Express.js is a minimal and flexible Node.js web application framework that provides robust
features for building web applications.
- Middleware functions have access to the request object, response object, and the `next()`
function in an Express app’s request-response cycle.
- Use custom error-handling middleware by defining a function with `(err, req, res, next)`.
- Routing is determining how an application responds to client requests for a specific URL path and
HTTP method.
- Use `express.static()` middleware to serve static assets like images, CSS, and JS files.
- By using middleware like `helmet`, enabling HTTPS, validating inputs, and setting up proper
authentication and authorization.
- 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`.
- It parses incoming JSON payloads and makes them available under `req.body`.
- JSX stands for JavaScript XML, a syntax extension that allows mixing HTML with JavaScript.
- Props are inputs passed to components to make them reusable and are read-only.
- State is an object that holds component-specific data that may change over time.
- Hooks allow functional components to use React features like state (`useState`) and lifecycle
(`useEffect`).
- 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
- `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.
- A feature that enables sharing state across multiple components without passing props manually
at every level.
- `useRef` is a hook that returns a mutable ref object whose `.current` property can be used to
access or modify a DOM element directly.
- A feature that allows rendering a component’s children into a DOM node outside the parent
hierarchy.
- A HOC is a function that takes a component and returns a new component, used to enhance
component functionality.
- `useMemo` is a hook that memorizes the result of a computation to optimize performance and
prevent unnecessary recalculations.
- By using techniques like memoization, lazy loading, code-splitting, and avoiding unnecessary re-
renders.
- Node.js is a JavaScript runtime that allows JavaScript code to be run on the server side, using
Chrome’s V8 engine.
- A mechanism that handles all asynchronous operations and callbacks in Node.js, ensuring non-
blocking I/O.
- `npm` is Node Package Manager, used to install, update, and manage dependencies in a Node.js
project.
- `require` is from CommonJS and is synchronous, while `import` is ES6 syntax that supports `tree-
shaking` and is asynchronous.
- Streams are a way to read or write data continuously and asynchronously in Node.js, used for
processing large data sets efficiently.
- A pattern where a single event listener is set for a parent element to handle events triggered by
its children, improving performance.
- Nodemon is a tool that automatically restarts a Node.js application when file changes are
detected, improving development workflow.
- Middleware functions process requests between the time they are received and sent as
responses, and are essential in Express.js for request handling.
- 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.
- `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.
- File uploads can be handled using middleware like `multer` to parse `multipart/form-data`.
- Deploy using cloud services such as Heroku, Vercel, or AWS, setting up the client and server to
run in a production environment.