The Wayback Machine - https://web.archive.org/web/20241001201320/https://www.geeksforgeeks.org/mean-stack/
Open In App

MEAN Stack

Last Updated : 29 Nov, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In the world of full-stack development, the MEAN stack has became one of the top choice for building dynamic and robust web applications. Web development refers to the creating, building, and maintaining of websites. It includes aspects such as web design, web publishing, web programming, and database management. This stack provides an end-to-end framework for the developers to work in and each of these technologies play a big part in developing websites of web applications. It comprises of 4 technologies namely: MongoDB, Express, Angular, and Node JS. It is designed to make the development process smoother and easier.

Roadmap-to-Mean-stack-developer-copy-(1)

What is MEAN Stack?

MEAN Stack is a JavaScript Stack that is used for easier and faster deployment of full-stack web applications. MEAN Stack comprises 4 technologies namely: MongoDB, Express.js, Angular.js, Node.js. It is designed to make the development process smoother and easier. It is one of the most demanded tech stack between developers for creating full fledge web applications. Although it is a Stack of different technologies, all of these are based on JavaScript language.

  • MongoDB: Non-relational open-source document-oriented database.
  • Express JS: Node.js framework that makes it easier to organize your application’s functionality with middleware and routing and simplify APIs.
  • Angular JS: It is a JavaScript open-source front-end structural framework that is mainly used to develop single-page web applications(SPAs).
  • Node JS: is an open-source and cross-platform runtime environment for building highly scalable server-side applications using JavaScript.

How MEAN stack works?

When working with MERN stack, developers create implement View layer using Angular, Express and Node are used to implement application layer of website then MongoDB is used to implement database layer.

Communication between these components happens via HTTP requests and responses. Angular, on the client-side, sends requests to the Express.js server, which interacts with MongoDB to fetch or modify data. The server then sends required data back to Angular for rendering.

How-MEAN-Stack-Works-copy

Roadmap to become a MEAN Stack Developer

Step 1: Learn basics of HTML, CSS and JavaScript

Step 2: Learn Angular which is a frontend library for building User Interfaces

Step 3: Learn Node JS which is JavaScript runtime environment

Step 4: Learn Express JS, a framework built upon Node.js to simplify the process of creating web application and API building

Step 5: Learn MongoDB, a NoSQL database to store and retrieve data.

Getting Started with MEAN Stack

There are two requirements to start a MEAN stack project:

Step 1: Install node on your system depending on your Operating System:

Step 2: You need a code editor to work with so install a code editor, preferably we will use VS Code

Setting Up a MEAN Stack Project

To setup MEAN stack we need to create a folder structure for both frontend and backend. Then we have to define database schema to store and retrieve data from the database.

Follow the below steps to create a basic structure

Step 1: After the code editor is installed, create a new project folder. Then go to the project folder in command prompt/terminal and type below commands to create folder for frontend and backend 

mkdir frontend
mkdir backend

Step 2: Navigate to the frontend folder using the command

cd frontend

Step 3: Initialize and run a Angular Project using the command

npm install -g @angular/cli
ng new my-angular-app
cd my-angular-app
ng serve --open

Step 4: Now navigate to the backend folder using the command

cd..
cd backend

Step 5: Initialize the project backend using the command

npm init -y

Step 6: Install Express and other backend dependencies using the command

npm i mongodb express cors dotenv  

After following all the above steps a basic structure for MERN Stack application is created.

Getting to know MEAN Stack components

1. MongoDB: Cross-platform Document-Oriented Database

MongoDB is a document-oriented NoSQL database system that provides high scalability, flexibility, and performance. Unlike standard relational databases, MongoDB stores data in a JSON document structure form. This makes it easy to operate with dynamic and unstructured data and MongoDB is an open-source and cross-platform database System.

Why use MongoDB? 

  • Fast – Being a document-oriented database, easy to index documents. Therefore a faster response.
  • Scalability – Large data can be handled by dividing it into several machines.
  • Use of JavaScript – MongoDB uses JavaScript which is the biggest advantage.
  • Schema Less – Any type of data in a separate document.
  • Data stored in the form of JSON.
  • Simple Environment Setup – Its really simple to set up MongoDB.
  • Flexible Document Model – MongoDB supports document-model(tables, schemas, columns & SQL) which is faster and easier.

Creating a database: Simply done using a “use” command:

use database_name;

Creating a table: If the collection/table doesn’t exist then a new collection/table will be created:

db.createCollection("collection_name");

Inserting records into the collection:

db.collection_name.insert
(
{
"id" : 1,
"Name" : "Klaus",
"Department": "Technical",
"Organization": "Geeks For Geeks"
}
);

Querying a document:

db.collection_name.find({Name : "Klaus"}).forEach(printjson);

Lightbox

Links to learn more about MongoDB:

2. Express: Back-End Framework:

Express is a small framework that sits on top of Node.js’s web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middle ware and routing. It adds helpful utilities to Node.js’s HTTP objects. It facilitates the rendering of dynamic HTTP objects.

Why use Express? 

  • Asynchronous and Single-threaded.
  • Efficient, fast & scalable
  • Has the biggest community for Node.js
  • Express promotes code reusability with its built-in router.
  • Robust API

Create a new folder to start your express project and type below command in the command prompt to initialize a package.json file. Accept the default settings and continue.

npm init

Then install express by typing the below command and hit enter. Now finally create a file inside the directory named app.js.

npm install express --save

Now type in the following in app.js to create a sample server.

app.js




const express=require('express'),
http=require('http');
const hostname='localhost';
const port=8080;
const app=express();
 
app.use((req, res)=> {
        console.log(req.headers);
        res.statusCode=200;
        res.setHeader('Content-Type', 'text/html');
        res.end('<html><body><h1>This is a test server</h1></body></html>');
});
const sample_server=http.createServer(app);
 
sample_server.listen(port, hostname, ()=> {
        console.log(`Server running at http: //${hostname}:${port}/`);});


Then to start the server by running the below command

node app.js
express-terminal

Express Terminal

Now you can open the browser and get the output of the running server.

express-browser

Express browser output

Links to learn more about ExpressJS:

3. Angular JS: Open Source Frontend Framework

Angular is a Front-end Open Source Framework developed by Google Team. This framework is revised in such a way that backward compatibility is maintained (If there is any breaking change then Angular informs it very early). Angular projects are simple to create using Angular CLI (Command Line Interface) tool developed by the Angular team.

Why use Angular.JS?

  • It follows a structured MVC architecture, which simplifies code organization and maintenance.
  • With HTML templates and built-in directives, it simplifies complex UI tasks and data binding.
  • Changes made are reflected instantly in the UI and vice versa, which reduces manual updates.
  • It uses modular and reusable components, which enhances testability and maintainability.
  • It utilizes TypeScript for strong typing and offers a powerful CLI for streamlined development, testing, and deployment tasks.

You can start your angular application by first installing “angualar-cli” using npm or yarn.

npm install -g @angular/cli

After that you can create a new angular app by using.

ng new my-angular-app

Now to run the application use the following command

cd my-angular-app
ng serve --open

Terminal Output:

ang-terminal

Angular terminal output

Browser Output:

angular

Angular Hello world

Links to learn more about Angular.js:

4. Node JS: JS Runtime Environment

Node.js is used to write the Server Side Code in Javascript. One of the most important points is that it is a runtime environment which runs the JavaScript code outside the Browser. It is cross-platform and Open Source. NodeJS is not a framework and it’s not a programming language. Node.js is used to build back-end services like APIs like Web App or Mobile App.

Why use Node.JS? 

  • Open-source JavaScript Runtime Environment
  • Single threading – Follows a single-threaded model.
  • Data Streaming
  • Fast – Built on Google Chrome’s JavaScript Engine, Node.js has a fast code execution.
  • Highly Scalable

Initialize a Node.js application by typing running the below command in the command window. Accept the standard settings.

npm init

Create a file named app.js. 

Example: A basic Node.js example to compute the perimeter & area of a rectangle.

app.js




let rectangle= {
    perimeter: (x, y)=> (2*(x+y)), area: (x, y)=> (x*y)
};
 
function Rectangle(l, b) {
    console.log("A rectangle with l = " +
        l + " and b = " + b);
 
    if (l <=0 || b <=0) {
        console.log("Error! Rectangle's length & "
        + "breadth should be greater than 0: l = "
        + l + ", and b = " + b);
    }
 
    else {
        console.log("Area of the rectangle: "
            + rectangle.area(l, b));
        console.log("Perimeter of the rectangle: "
            + rectangle.perimeter(l, b));
    }
}
 
Rectangle(1, 8);
Rectangle(3, 12);
Rectangle(-6, 3);


Run the node application by running the below command in the command window.

node app.js

Output:

node-output

Node terminal Output

Links to learn more about Node.js:

Benefits of learning MEAN stack

  • Full JavaScript Stack: The MEAN stack is entirely JavaScript-based, both on the client and server sides. This means developers can use a single language, JavaScript, throughout the entire application stack.
  • Real-time Web Applications: Node.js is excellent for building real-time applications. When combined with technologies like WebSockets, it allows for bidirectional communication between the client and server.
  • Scalability and Performance: The MEAN stack is known for its scalability. Node.js is designed to handle concurrent connections efficiently, while MongoDB’s horizontal scalability allows for distributed database setups, making it easier to scale applications.
  • Community and Ecosystem: The MEAN stack has a vast and active developer community, which facilitate extensive resources, libraries, and frameworks available for support.
  • Rapid Development and Code Reusability: Angular’s component-based architecture and Node.js’s event-driven nature helps in rapid development. Additionally, code components can often be reused across different layers of the application.


Similar Reads

Difference between MEAN Stack and Full Stack Developer
MEAN Stack Developer : An IT professional who works on a collection of JavaScript technologies to develop web applications is called a MEAN stack developer. MEAN refers to M for MongoDB (NoSQL database)E for Express (a backend web application framework for Node.js)A for Angular (JavaScript based open-source frontend web framework to develop single
3 min read
Difference between MEAN Stack and MEEN Stack
What are stacks? What is a stack, if you are familiar with full-stack development you might have come across the terms MEAN, MERN, MEVN, MEEN, etc. These are web stacks consisting of a collection of software and frameworks used for building a web application from the front-end and back-end. You can learn any of these stacks to become a Full-stack d
4 min read
Difference between MEAN Stack and MERN Stack
Web development is a procedure or process for developing a website. A website basically contains three ends: the client side, the server side, and the database. These three are different sides of an application that combine together to deliver an application; all ends are implemented separately with different technologies. MEAN and MERN are the tec
3 min read
Difference between MEAN Stack and LAMP Stack Developer
MEAN Stack and LAMP Stack are two popular technology stacks used for web application development, each offering distinct advantages and components. MEAN Stack consists of MongoDB, Express.js, Angular (or AngularJS ), and Node.js while LAMP Stack comprises Linux, Apache, MySQL and PHP/Perl/Python , known for its versatility in traditional web applic
6 min read
What is the difference between MEAN.js and MEAN.io?
MEAN (MongoDB, Express.js, AngularJS (or Angular), and Node.js) is a free and open-source software stack for building dynamic web sites and web applications. The acronym MEAN was given by Valeri Karpov when he introduced the term first time in a blog post in 2013. The framework uses JavaScript for both client and server-side interaction. The framew
3 min read
Introduction to MEAN Stack
MEAN Stack is one of the most popular Technology Stack. It is used to develop a Full Stack Web Application. Although it is a Stack of different technologies, all of these are based on JavaScript language. MEAN Stands for: M - MongoDB E - Express A - Angular N - Node.js This stack leads to faster development as well as the deployment of the Web Appl
5 min read
Summarizer Website using MEAN Stack
This article aims to develop a project using MEAN stack which will work as a summarizer website. MEAN stack technologies include MongoDB, AngularJS, NodeJS, and Express. It will give you a thorough understanding of how to create a MEAN stack application end to end from backend to frontend including the user authentication feature. Output Preview: L
15+ min read
Community Forum Page using MEAN Stack
Creating a community forum page using the MEAN (MongoDB, Express.js, Angular, Node.js) stack will clear the concepts of MEAN stack. It will help strengthen the understanding of CRUD operations. This article will discuss about the features of creating, updating, deleting a post, like / unlike feature, getting the complete post list, and retrieving t
15+ min read
Product Review Platform using MEAN Stack
In today's digital age, online reviews play an important role in shaping consumer decisions. Whether it's choosing a restaurant, purchasing a gadget, or booking a hotel, people often rely on the experiences and opinions shared by others. In this article, we'll explore how to create a dynamic and user-friendly product review platform using the MEAN
15+ min read
Health Tracker using MEAN Stack
In the fast-paced world, maintaining a healthy lifestyle is more important than ever. Technology can play a significant role in helping individuals monitor and improve their health. In this article, we'll explore how to use the power of the MEAN (MongoDB, Express.js, Angular, Node.js) stack to build a robust and feature-rich Health Tracker applicat
15+ min read
Stock Market Portfolio App using MEAN Stack
In this guide, we'll walk through the process of building a stock market application using Angular, a powerful front-end framework. Building a stock market application allows users to monitor stock prices, add stocks to their watchlist, and stay informed about market trends. Project Preview: Prerequisites:Basic knowledge of HTML, CSS, and JavaScrip
6 min read
Hospital Management System using MEAN Stack
The Hospital Management App is an important application that ensures seamless coordination to revolutionize healthcare administration. In this article, we will be creating a Hospital Management Website using the MEAN stack – i.e. MongoDB, Express, Angular, and Node.js, with step by step process for easy understanding. Project Preview: Prerequisite:
15+ min read
Twenty-one Game using MEAN Stack
Twenty-one Game is a popular card game played in casinos worldwide. In this article, we'll explore how to create a Twenty-one game also known as the BlackJack game using the MEAN stack (MongoDB, Express.js, Angular, and Node.js). By building a Twenty-one game, we'll see the various aspects of web development with the MEAN stack. Project Preview: Pr
8 min read
Bookstore Ecommerce App using MEAN Stack
In this article, we will build a simple yet powerful bookstore application using Angular for the front end and Node.js for the back end. This project application will showcase how to set up a full-stack web application where users can view, filter, and purchase various books. Project Preview: PrerequisitesNode.js and npm (Node Package Manager)Angul
8 min read
Blackjack Game using MEAN Stack
This is a project to get a thorough understanding of MEAN Stack technologies (MongoDB, Express, Node JS, Angular). This will give you a step-by-step process to create a blackjack game from scratch. This article will discuss Starting a new game, the logic to play it and store it in the database. It will also help you to understand the CRUD operation
15+ min read
Todo List Application using MEAN Stack
The todo list is very important tool to manage our tasks in this hectic schedule. This article explores how to build to-do list application using the MEAN stack—MongoDB, Express.js, Angular, and Node.js. We’ll walk you through the process of setting up backends with Node.js and Express.js, integrating MongoDB for data storage efficiency, and using
10 min read
MEAN Stack Projects with Source Code
The MEAN stack, comprising MongoDB, Express JS, Angular, and Node JS, is a powerful combination that enables developers to build full-stack web applications using JavaScript. MongoDB serves as the database, Express.js handles server-side logic, Angular manages the client-side interface, and Node.js facilitates backend operations. This article delve
2 min read
Difference between LAMP stack and LEMP stack?
Difference between LAMP and LEMP stack :A Web Stack or Web application stack refers to a compilation of software that is together used to build websites or web applications. To construct a stack basic requirements are : Operating SystemWebserverDatabaseScript Interpreter 1. LAMP Stack :LAMP stack is a collection of Linux OS, Apache Server, MySQL Da
4 min read
MERN Stack vs Java Full Stack
A website is a collection of various web pages made by the most popular technologies, like HTML, CSS, and JavaScript, along with other front-end and back-end technologies. A website contains primarily three sides: a client side, a server side, and a database. When it comes to the three sides of a website complete together, it is called a stack. In
6 min read
D3.js | d3.mean() function
The d3.mean() function in D3.js is used to return the mean or average of the given array's elements. If the array is empty then it returns undefined. Syntax: d3.mean(Array) Parameters: This function accepts a parameters Array which is an array of elements whose mean are to be calculated. Here elements should be integers not string otherwise it retu
2 min read
What does it mean to start a PHP function with an ampersand?
An ampersand just before the function name will return a reference to the variable instead of returning its value. Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. In PHP 4, objects were assigned by value, just like any oth
2 min read
What does +_ operator mean in JavaScript ?
Unary Operator: A unary operation contain only one operand. Here, the '+' unary plus operator converts its operand to Number type. While it also acts as an arithmetic operator with two operands which returns an addition result on calculation. JavaScript Identifiers: Javascript Identifiers are used to name variables (and keywords, functions, and lab
2 min read
Tensorflow.js tf.mean() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.mean() function is used to calculate the mean value of the specified Tensor across its dimension. It reduces the given input elements along the dimensions of axes. If the parame
2 min read
Explain mean of 404 not found HTTP response code ?
The browser and the site server have a conversation in the form of HTTP status codes. The server gives responses to the browser’s request in the form of a three-digit code known as HTTP status codes. The categorization of HTTP status codes is done in five sections which are listed below. Informational responses (100–199)Successful responses (200–29
2 min read
What do you mean by jQuery traversing ?
jQuery traversing means moving through the linked elements in an HTML page. Using jQuery traversing, we can search and find different elements based on the relation of the elements. The elements can be parents, siblings, children, etc. We can move up (ancestors), down (descendants), and sideways (siblings). We can see a DOM in the following diagram
9 min read
What does the mean of pipe (|) symbol in Typescript ?
In Typescript, pipe(|) is referred to as a union type or "Or". it is also called union type in typescript. A value that can be any of numerous kinds is described by a union type. Each type is separated by a pipe (|), thus the number| string represents a value whose type can be a string or a number. or we can say either of the specified types is per
3 min read
What does enctype='multipart/form-data' mean in an html form ?
When building a web application, it's common to include forms that allow users to submit information. HTML forms can be used to send data to a server for processing, but it's important to specify the encoding type of the form. The enctype attribute is used to specify the encoding type of an HTML form. The enctype attribute specifies how the form da
3 min read
What do you mean by Asynchronous API ?
Asynchronous APIs are widely utilized in modern development because of their ability to handle multiple requests simultaneously, which improves the overall user experience. In this article, we will look into asynchronous APIs, their advantages, and how to implement them. What are Asynchronous APIs? Asynchronous APIs are a sort of web service that a
3 min read
MEAN Full Form
MEAN Stack is a JavaScript Stack that is used for easier and faster deployment of full-stack web applications. It comprises of 4 technologies namely: MongoDB, Express, Angular, and Node JS. It is designed to make the development process smoother and easier. Table of Content MEAN Full FormWhat is MEAN stack?Benefits of learning MEAN stack?MEAN Full
5 min read
What does !== undefined mean in JavaScript ?
In JavaScript, !== is a strict inequality operator, and undefined is a special value representing the absence of a value or the lack of an assigned value to a variable. The !== operator checks for both value and type equality, and !== undefined is used to verify if a variable is not equal to the undefined value. Table of Content Using Strict Inequa
1 min read
Article Tags :