Let Understand MERN Stack In Practical way
Tags: webdev, javascript, beginners, programming
Published: 2024-04-08 06:49:10

MERN stands for MongoDB, Express.js, React.js, and Node.js. It's important because it helps us build powerful web applications. 

Imagine we're running a company and we want to keep track of our employees' information, like their names, emails, phone numbers, salaries, and how often they come to work.

Here's how we can see the information about our employees:

👀 Look at this table:

| Name         | Email                    | Phone          | Salary   | Attendance |
|--------------|--------------------------|----------------|----------|------------|
| John Smith   | john.smith@example.com  | +1234567890    | $60,000  | 95%        |
| Emily Johnson| emily.johnson@example.com| +1987654321    | $55,000  | 98%        |
| Michael Brown| michael.brown@example.com| +1654321890    | $65,000  | 92%        |
| Sarah Lee    | sarah.lee@example.com   | +1765432980    | $70,000  | 96%        |
| David Wilson | david.wilson@example.com| +1876543210    | $75,000  | 97%        |

## MONGODB

Now, to keep this information safe and organized, we need to put it in a special place called a database. We can use databases like MongoDB or MySQL for this.

So, MERN helps us make sure all the information about our employees is kept safe and easy to find whenever we need it.


## Nodejs

Imagine you have a magical toolbox called Node.js. This toolbox lets you do special things on your computer or server, like making apps or websites. But instead of using regular tools like hammers or screwdrivers, Node.js lets you use JavaScript, the language of the web.

With Node.js, you can do cool stuff like:

**Run JavaScript Outside of Browsers:** Normally, JavaScript runs inside web browsers, but with Node.js, you can run JavaScript code directly on your computer or server.

**Build Web Servers:** You can create your own web server to handle requests from web browsers, which means you can make your own websites and web apps.

**Access Files and Databases:** Node.js lets you read and write files on your computer and connect to databases like MongoDB or MySQL.

So, Node.js is like a magical toolbox that empowers you to do all sorts of cool things with JavaScript on your computer or server.

## Express.js:

Now, let's talk about Express.js. Imagine you have a super smart assistant called Express.js. This assistant helps you build web applications quickly and easily.

Here's how Express.js works:

**Simplifies Web Development:** Express.js provides a set of tools and shortcuts to make it easier to build web applications with Node.js. It saves you time and effort by handling common tasks, like routing and handling HTTP requests.

**Middleware:** Express.js uses middleware, which are like small plugins or functions that you can use to add extra features to your web app, such as authentication, logging, or error handling.

**Routing:** With Express.js, you can easily define routes for different URLs in your web app. For example, you can create a route for "/login" to handle user login requests or a route for "/products" to display a list of products.

**Integration:** Express.js works seamlessly with other Node.js modules and libraries, making it easy to add additional functionality to your web app.

So, Express.js acts as a smart assistant that helps you build web applications faster and with less effort by providing tools, middleware, and routing capabilities.

## React:

Imagine you have a magical toolkit called React. This toolkit helps you build amazing user interfaces for your websites or web applications. It's like having a set of super-powered building blocks that you can use to create all kinds of cool things on the web.

With React, you can do awesome stuff like:

**Component-Based Development:** React lets you break down your user interface into smaller, reusable components. Each component represents a part of your UI, like a button, form, or header. You can then combine these components to build complex UIs, making your code more modular and easier to maintain.

**Virtual DOM:** React uses a virtual representation of the DOM (Document Object Model), which is like a blueprint of your UI. When your data changes, React updates only the parts of the DOM that need to change, making your apps faster and more efficient.

**Declarative Syntax:** React uses a declarative syntax, which means you describe what you want your UI to look like, and React takes care of updating the DOM to match. This makes it easier to reason about your code and write cleaner, more maintainable UIs.

So, React is like a magical toolkit that empowers you to build interactive and dynamic user interfaces for your web applications with ease.

## Client:

Now, let's talk about the client. Imagine you have a friendly guide called the client. The client is like a person who interacts with your website or web application using a web browser, like Chrome or Firefox.

Here's how the client works:

**Accessing Web Content:** The client opens a web browser and types in a web address (URL) to access your website or web app. Once connected, the client can view and interact with the content you've created using technologies like HTML, CSS, and JavaScript.

**Sending and Receiving Data:** The client can send requests to your web server to fetch data or perform actions, like submitting a form or logging in. It then receives responses from the server, which it can display or use to update the UI.

**Interactivity:** The client can interact with your web app by clicking on buttons, filling out forms, or navigating between pages. It can also respond to user input, like keyboard or mouse events, to provide a dynamic and engaging user experience.

So, the client is like a friendly guide that helps users interact with your website or web application, enabling them to access content, send and receive data, and engage with the UI in meaningful ways.

## Server:

Imagine you have a helpful butler called the server. The server is like a dedicated assistant that works behind the scenes to handle requests and deliver information to your website or web application.

Here's how the server works:

**Handling Requests:** When the client (the person using a web browser) wants to access your website or web app, they send a request to the server. This request includes things like the web address (URL) they want to visit or the data they want to retrieve.

**Processing Requests:** Upon receiving a request, the server swings into action. It processes the request, which might involve fetching data from a database, running calculations, or performing other tasks needed to fulfill the client's request.

**Sending Responses:** Once the server has processed the request and gathered the necessary information, it sends a response back to the client. This response contains the requested data or instructions on what to display in the web browser.

**Managing Resources:** The server also manages resources like files, databases, and other services needed to run your website or web app. It ensures that everything runs smoothly and efficiently to provide the best possible experience for users.

So, the server is like a helpful butler that works tirelessly behind the scenes to handle requests, process data, and deliver information to users, ensuring that your website or web application functions smoothly and reliably.