Amazon EC2 Tutorial : Hosting Mean Stack Application
Amazon EC2 is one of the most used and most fundamental services in AWS, so it makes sense to start there when you are new to the platform. But the first question is: what is EC2 in AWS?
![]() |
| Amazon EC2 — Hosting a MEAN Stack Application |
The below topics are covered in this blog -
1) What is EC2 in AWS?
2) The MEAN stack CRUD application
3) Architecture of the application
4) Installing MongoDB on an EC2 instance
5) Hosting the MEAN stack with PM2
1. What is EC2 in AWS?
To keep it simple:
- EC2 is basically a virtual machine with its own CPU, RAM, and storage.
- It lets you choose a platform — Windows, Linux, Ubuntu, and so on — when you launch the machine in the cloud.
- Each virtual machine is called an instance, and you can start, stop, or terminate it whenever you like.
2. AWS EC2 MEAN Stack Application Screens
Here are a few screens from the MEAN stack CRUD application we are going to host on AWS EC2.
Insert
![]() |
| MEAN Stack CRUD Application — Insert |
Update
![]() |
| MEAN Stack CRUD Application — Update |
Delete
![]() |
| MEAN Stack CRUD Application — Delete |
3. Architecture of the MEAN Stack Application
The diagram below shows the architecture we are setting up across two AWS instances. The frontend uses Angular, and every user interaction — create, read, update, delete — goes through Node.js.
![]() |
| MEAN Stack Application Architecture |
Node.js acts as the mediator that talks to the MongoDB database and returns data to the frontend. We use two instances — one for the frontend and one for the backend.
MEAN stack frontend project:
git clone https://bitbucket.org/atique12/mongocrud_application_frnt_end.git
MEAN stack backend project:
git clone https://bitbucket.org/atique12/mongocrud_application_back_end.git
If you want to learn more about the MEAN stack, see my related blog post: MEAN Stack Angular CRUD Application.
4. Installing MongoDB on an AWS EC2 Instance
If you haven't registered on AWS yet, do that first. Then launch an Ubuntu instance, download the PEM key, and open your terminal:
ssh -i yourkey.pem ubuntu@your_ec2_public_ip
Once you are logged in, install MongoDB. Reference links:
MongoDB — Install MongoDB Community Edition
GUI client — Robo 3T (formerly Robomongo)
Reference repository for this tutorial:
git clone https://bitbucket.org/atique1224/aws-ec2-tutorial.git
5. Hosting the MEAN Stack with PM2
On the second Ubuntu instance, install Node.js, NVM, the Angular CLI, and PM2, then clone the code onto the instance.
Install Node.js
sudo apt update
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
Install NVM (to switch Node.js versions)
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.profile
nvm ls-remote
Install the Angular CLI
sudo npm install -g @angular/cli
Install PM2 (to keep the app running)
sudo npm install -g pm2
Clone both projects
git clone https://bitbucket.org/atique12/mongocrud_application_frnt_end.git
git clone https://bitbucket.org/atique12/mongocrud_application_back_end.git
Point the code at your instances. By default the projects use localhost. You need to replace that with your EC2 public IPs:
- Backend — in
db.js, set the MongoDB instance's public IP; inindex.js, set the backend instance's public IP. - Frontend — in
src/app/shared/person.services.ts, changelocalhostto the backend instance's public IP:
vi src/app/shared/person.services.ts
One important note: pointing the frontend at a raw EC2 public IP hardcodes an address that changes every time the instance restarts, unless you attach an Elastic IP. For anything beyond a demo, put the backend behind a stable hostname or load balancer rather than baking the IP into your source.
6. Video Walkthrough
More videos in this series:





9 comments :
It is commonly confounded to plainly characterize explicitly what the best web facilitating truth be told is however there are a couple of rules it is not difficult to stay with that can assist you with discovering what the best web facilitating is https://onohosting.com/intended for your necessities.
your content is very inspiring and appriciating I really like it please visit my site for Satta King Result also check Satta king 24X7 and also check sattaking and for quick result check my site Satta matka and for super fast result check Satta king
This article provides good overview of motives of Singapore Workpass Application
The best MEAN Stack Training in Gurgaon offer hands-on experience with real-world projects, so you can gain practical experience and build a strong foundation in MEAN stack. In addition, many training institutes offer job placement assistance to help students find jobs after completing their training
I'm delighted to discover this post immensely valuable, given its wealth of information. I consistently prioritize reading high-quality content, and I've certainly found that in your post. Thank you for sharing. ZoopUp.
Unlock the full potential of JavaScript with APTRON Gurgaon's comprehensive NodeJs Course in Gurgaon. Designed for both beginners and experienced developers, this course provides hands-on training in building scalable, fast, and real-time web applications. Whether you are looking to enhance your skillset or start a career in backend development, APTRON Gurgaon ensures you are industry-ready with expert guidance and practical exposure.
This is a practical and useful walkthrough of hosting a MEAN stack application on Amazon EC2, especially because it covers both the application architecture and the actual deployment steps. The separation of frontend and backend across EC2 instances also makes the deployment approach easy to understand.
The combination of Angular, Node.js, and MongoDB is clearly explained through the CRUD application architecture, making MEAN Stack Course a natural fit for developers who want to understand how these technologies work together as a complete stack.
The frontend deployment process is also practical, with Angular CLI installation and configuration covered as part of the EC2 setup. Developers looking to strengthen their frontend skills can benefit from Angular Training when building applications that communicate with a Node.js backend.
On the backend side, Node.js serves as the mediator between the Angular frontend and MongoDB database, while PM2 is used to keep the application running. This makes Nodejs Course relevant for understanding the server-side development and deployment concepts demonstrated in the tutorial.
Post a Comment