Table of Contents
Step 1: Provision an AWS Instance
Step 2: Install Node.js
Step 3: Install MongoDB
Step 4: Install Express and Set Up Routes
Step 5: Access the Routes with AngularJS
Step 6: Run the App
Deploying a Web Book Register Application on an Ubuntu AWS EC2 instance using the MEAN stack (MongoDB, Express, Angular, Node.js) involves several steps. Here’s a step-by-step guide:
Step 1: Provision an AWS Instance
Launch an EC2 Instance:
- Use the AWS Console to launch an Ubuntu Server (e.g., 22.04 LTS).
- Choose an instance type (e.g., t2.micro for free tier).
- Configure security groups to allow:
SSH (port 22) for server access.
HTTP (port 80) and HTTPS (port 443) for web traffic.
- Connect to the Instance:
Step 2: Install Node.js
Node.js is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.
- Update System Packages:
- Add certificates:
- Install Node.js:
Step 3: Install MongoDB
Follow these steps to install MongoDB Community Edition using the apt package manager.
- Install gnupg and curl if they are not already available:
- Create the List File Create the list file for Ubuntu 24.04 (Noble):
- Reload the Package Database Issue the following command to reload the local package database:
- Install MongoDB Community Server You can install either the latest stable version of MongoDB or a specific version of MongoDB.
- Init System
To run and manage your mongod process, you will be using your operating system's built-in init system.
If you are unsure which init system your platform uses, run the following command:
- Start and verify MongoDB. You can start the mongod process and Verify that MongoDB has started successfully by issuing the following commands:
- Install npm (Node Package Manager):
Note: I faced issues with installing the npm, so I used aptitude to Resolve Dependencies. If you face issues, you can try using aptitude (an alternative package manager) to handle the dependency resolution:
aptitude:
- Install aptitude:
Then, try installing npm using:
- Install the body-parser package:
- Create a folder for the project:
- Initialize the npm project:
- Create a file named server.js and add the following code:
Step 4: Install Express and Set Up Routes
- Install Express and Mongoose:
- Create a folder named apps:
- Create a file named routes.js and add the following code:
- Create a folder named models:
- Create a file named book.js and add the following code:
Step 5: Access the Routes with AngularJS
- Change the directory back to Books:
- Create a folder named public
- Create a file named script.js and add the following code:
- In the public folder, create a file named index.html and add the following code:
Step 6: Run the App
- Go back to the project root directory and run the following command:
- Opening TCP port 3300 on AWS Web Console for your EC2 Instance to access it from the Internet.
- Accessing the Book Register Application by opening a browser and going to http://:3300
- Testing the Book Management Application:
Top comments (0)