This post will show you how we can quickly create a node.js web aplication based on express framework and how to deploy that application on AWS using AWS BeanStalk service.
Now first you need to know what is AWS BeanStalk?
Some information about AWS BeanStalk:
- AWS BeanStalk is the fastest and simplest way to deploy your application on AWS.
- Under the covers, it is simply running your code on EC2 instances.
- It automatically scales your application up and down.
- Basically here you can select your EC2 instance type that is optimal for your application.
- It can deploy apps built over popular frameworks like Java, node.js, PHP etc. and servers like Apache Tomcat, IIS, Passenger etc.
So let us get started!
Step 1: Creating an web application in node.js – express framework.
To create a express application skeleton we need to install express generator from npm:
Check available option while creating an express app:
After installing the express generator, we will create an express sample application:
Now go to the application folder and install dependencies:
On Mac OS or Linux, run the app with this command
On Windows, use this command:
The generated app has the following directory structure:
Then load http://localhost:3000/ in your browser to access the app.
I added some text and picture and a button to make it like a web app.
OK, now our express app is created and running on localhost.
Let us go to our AWS Management Console and see how to deploy this app on AWS BeanStalk.
Step 1) Go Service and Click on AWS BeanStalk under Compute.
As shown below:
Step 2) Now click on Get Started button, as shown below:
Step 3) Fill the details as shown below:
Click on upload button to upload you code in a zip file.
Click on upload.
Then click on Create Application button
This will upload your codebase in S3 bucket and deploy your application.
This takes around 5-10 mins.
Once your app is deployed you will see the dashboard showing Health, status, EC2 instance name, Machine name etc details.
Click on URL present on the dashboard and you can see your app running.
So that is end of this post..
Hope you all learned and enjoyed this one.
Post you queries in the comments section below.