DEV Community

Syed Muhammad Ali Raza
Syed Muhammad Ali Raza

Posted on

MERN Basics An Introduction to Full Stack JavaScript Framework

Introduction:

In the world of web development, staying up-to-date with the latest frameworks and technologies is essential. One such popular framework that has gained immense popularity is MERN, which stands for MongoDB, Express.js, React.js and Node.js. MERN is a full stack JavaScript framework that enables developers to build robust and scalable web applications. In this article, we'll explore the basics of MERN and understand how these technologies work together to create dynamic and interactive web applications.

MongoDB:
MongoDB is a NoSQL database that forms the "M" in MERN. Unlike traditional relational databases, MongoDB stores data in flexible JSON-like documents called BSON. It offers high scalability, automatic sharing and replication, making it an excellent choice for processing large amounts of data. MongoDB's flexible data model allows developers to work with dynamic schemas, making it easy to adapt and evolve applications over time.

Express.js:
Express.js, also known as Express, is a fast and minimalistic web application framework for Node.js. It provides a robust set of features for building web servers and APIs. With Express, developers can easily handle routes, middleware, and HTTP requests. Express.js simplifies the process of building server-side applications by providing a lightweight framework that enables rapid prototyping and scaling.

React.js:
React.js, commonly referred to as React, is a popular JavaScript library for building user interfaces. It allows developers to create reusable UI components that efficiently update and render based on data changes. React follows a component-based architecture, which makes it easy to build complex user interfaces by composing smaller, reusable components. React's virtual DOM efficiently updates only the necessary parts of the UI, resulting in improved performance and a smooth user experience.

Node.js:
Node.js is a JavaScript runtime built on the Chrome V8 JavaScript engine. It allows developers to run server-side JavaScript code, enabling the development of scalable and high-performance web applications. Node.js provides an event-driven, non-blocking I/O model, making it ideal for handling concurrent connections and real-time applications. With Node.js, developers can create back-end APIs and server-side logic that seamlessly integrates with a front-end built using React.

Putting it all together:

  • MERN is a powerful combination of these technologies that enables developers to create complex JavaScript applications. Here's how they work together:

  • Node.js serves as a back-end runtime environment that handles server-side logic and API requests.
    Express.js provides a minimalistic and flexible framework for building web servers and handling routes and middleware.

  • MongoDB acts as a database and efficiently stores and retrieves data in JSON-like documents.
    React.js takes care of the front-end user interface and provides a reactive and component-based approach to building dynamic web applications.

MERN Basic Code

Node Js :

`// server.js

const Express = request ( 'Express' );
const program = express();

// API endpoint
app.get('/api/data', (req, res) => {
const data = {
message: 'Hello, MERN!'
};
res.json(data);
});

// Start the server
const port = 5000;
app.listen(port,() => {
console.log(Server running on port ${port});
});

*React js *

`// App.js

import React, { useState, useEffect } from 'react';

const App = () => {
const [message, setMessage] = useState('');

useEffect(() => {
fetchData();
}, []);

const fetchData = async () => {
Try {
const response = await fetch('/api/data');
const data = await response.json();
setMessage(data.message);
} catch (error) {
console.log(error);
}
};

return (


MERN Basics


{message}



);
};

export the default application;`

index.js
// index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(, document.getElementById('root'));

node server.js

Conclusion:

MERN is a versatile and comprehensive full-stack JavaScript framework that enables developers to create modern, scalable and efficient web applications. By combining the power of MongoDB, Express.js, React.js, and Node.js, developers can build robust applications that seamlessly handle both server-side and client-side aspects. Whether you are an experienced developer or just starting your web development journey, mastering the MERN stack will undoubtedly open up exciting opportunities in the world of full stack JavaScript development.

Top comments (0)