image

MEAN Stack

23 Oct, 2023 Abdelrahman Etry

The MEAN Stack, consisting of MongoDB, Express, AngularJS, and Node.js, has gained immense popularity in the last few years. With its scalable, real-time nature, it offers an excellent choice for web developers to create powerful and interactive web applications.


A Brief Overview of Each Component

  1. MongoDB : A popular NoSQL database that allows developers to store and manipulate data in a flexible, JSON-like format. It supports complex queries and offers excellent performance for read and write operations.
  2. Express : A lightweight, server-side web application framework for Node.js. It simplifies the process of building web applications by providing a set of robust features, such as routing, middleware support, and template engines.
  3. AngularJS : A powerful, client-side JavaScript framework for building interactive, single-page web applications. It offers two-way data binding, which enables the automatic synchronization of data between the model and the view, resulting in a more dynamic and responsive user experience.
  4. Node.js : A runtime environment for executing JavaScript code on the server side. It enables developers to write full-stack JavaScript applications, leveraging the same language for both front-end and back-end development.


Building a Simple MEAN Stack Application

In this section, we will demonstrate how to build a basic MEAN Stack application using MongoDB as the database, Express for routing, AngularJS for the front-end, and Node.js for server-side processing.


1. Setting up the Environment

First, you need to install Node.js, npm (Node Package Manager), and MongoDB on your machine. You can find the installation instructions on the official websites of each component.


2. Creating a New Project

Use the following command to create a new project directory:
mkdir mean-app
cd mean-app


3. Initializing the Project

Run the following command to create a package.json file:
npm init


4. Installing Dependencies

Use the following command to install Express and AngularJS
npm install express angular --save


5. Building the Server

Create a new file called app.js and add the following code
  var express = require('express');
  var app = express();

  app.use(express.static(__dirname + '/public'));

  app.get('/', function(req, res) {
      res.sendFile(__dirname + '/public/index.html');
  });

  app.listen(3000, function() {
      console.log('App listening on port 3000');
  });



6.  Building the Client

In the public folder, create an index.html file and add the following code:
<!DOCTYPE html>
  <html ng-app>
  <head>
      <title>MEAN Stack App</title>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
  </head>
  <body>
      <h1>Welcome to the MEAN Stack App!</h1>
  </body>
  </html>


Running the Application

1. Starting the Server

Open a terminal window and navigate to the project directory. Then, run the following command to start the server:
node app.js


2.  Accessing the Application

Open a web browser and navigate to http://localhost:3000. You should see the "Welcome to the MEAN Stack App!" message displayed on the page.


Conclusion

In this article, we explored the fundamentals of the MEAN Stack and demonstrated how to build a simple application using this technology stack. By combining MongoDB, Express, AngularJS, and Node.js, the MEAN Stack provides a comprehensive solution for creating modern, interactive web applications. For further reading and to deepen your understanding of the MEAN Stack. MEAN Stack offers a robust and scalable solution for developing modern web applications. With its wide range of libraries and resources, the MEAN Stack community continues to grow and innovate, providing developers with unprecedented opportunities for success.


Useful Links




Recent Posts
image

Laravel Livewire

12 Sep, 2024 Abdelrahman Etry
image

Deployment with Envoyer and Laravel

30 Oct, 2023 Abdelrahman Etry
image

Laravel Request Lifecycle

28 Oct, 2023 Abdelrahman Etry
image

Laravel Queues: Everything You Need to Know

28 Oct, 2023 Abdelrahman Etry
image

Laravel Repository Pattern

28 Oct, 2023 Abdelrahman Etry
image

Laravel Packages You Should Know About

26 Oct, 2023 Abdelrahman Etry