Mern
Mern
answers:
1. What is MongoDB?
MongoDB is a NoSQL, document-oriented database** that stores data in a
flexible, JSON-like format called **BSON**. It allows for dynamic schemas,
meaning fields and data types can vary across documents, making it suitable
for handling unstructured or semi-structured data.
2. What is a NoSQL database, and how does MongoDB fit into this category
NoSQL databases provide a way to store and retrieve data that does not follow
the relational table-based structure. MongoDB is a **NoSQL database**
because it is schema-less, allowing documents to have different fields, and
stores data in a **document model** (BSON) instead of rows and columns
---
Here are key **Node.js interview questions** along with summarized answers:
Summary promise
---
12. **What is the virtual DOM, and how does React use it?**
- **Answer:** The **virtual DOM** is a lightweight representation of the
actual DOM. When a React component's state changes, React creates a virtual
DOM tree, compares it to the previous one (using a diffing algorithm), and
updates only the changed elements in the actual DOM, which makes the
rendering efficient.
---
16. **What is Node.js, and how does it work in the MERN stack?**
- **Answer:** Node.js is a runtime that allows you to run JavaScript on the
server-side. In the MERN stack, Node.js handles server-side operations,
including serving static files, handling API requests, and interacting with the
database (MongoDB).
---
20. **How does the front-end (React) communicate with the back-end
(Node.js/Express)?**
- **Answer:** The front-end communicates with the back-end using HTTP
requests (GET, POST, PUT, DELETE). Axios or the Fetch API is commonly used in
React to send these requests to Express APIs.
```js
axios.get('/api/users')
.then(response => setUsers(response.data));
```
22. **What is CORS, and how do you handle it in a MERN stack app?**
- **Answer:** CORS (Cross-Origin Resource Sharing) is a security feature
that prevents one domain from accessing resources on another domain. In a
MERN app, you configure CORS in the back-end using middleware:
```js
const cors = require('cors');
app.use(cors());
```
2. **HTTP Methods**:
- **GET**: Retrieve data from the server (e.g., get a list of products).
- **POST**: Send data to the server to create a new resource (e.g., add a
new user).
- **PUT/PATCH**: Update an existing resource (e.g., modify a user profile).
- **DELETE**: Remove a resource from the server (e.g., delete a product).
3. **Statelessness**: REST APIs are stateless, meaning each request from the
client contains all the necessary information, and the server does not store any
client context between requests.
4. **Endpoints**: The URLs that represent resources. For example:
- `GET /users` – retrieves all users
- `POST /users` – creates a new user
REST is widely used due to its simplicity and scalability, making it ideal for
building web services and APIs.