We will create a fresh NodeJS application, then deploy it on AWS Elasticbeanstalk. We will also deploy an updated version of the application.
Create a Node Express Application
Install Express Generator
npm install express-generator -g
This will install
express-generator globally, allowing you to make use of the
express command on the terminal.
Create Express Project
This bootstraps a new express project named
node-elasticbeanstalk in the
Install NPM packages
Navigate to the directory and install npm dependencies:
cd node-elasticbeanstalk && npm install
Start the server by running the command:
Then navigate to http://localhost:3000 in your browser.
Set Up AWS Elasticbeanstalk Environment
If you do not already have an AWS account, you need to sign up here. This will give you access to Elasticbeanstalk and other AWS Services.
Create an Elasticbeanstalk Application
Open the AWS console and navigate to the Elasticbeanstalk service.
Click on the Get Started button. You will be directed to create a web app.
Give a name to your application. In this case, i have named mine
node-elasticbeanstalk. Also, select
Node.Js as the platform. Then select “Upload your code” in the application code section.
Prepare NodeJS Application for Deployment
Create a Zip of NodeJs App
We have to create a zip file of our entire NodeJS application files, excluding the
node_modules folder. The node_modules folder is excluded because Elasticbeanstalk automatically runs node dependency installation for your application.
Note that you should not zip the parent
node-elasticbeanstalk folder, instead create a zip of the application files themselves by selecting them and choosing compress.
Once the zip file is ready, click on the “Upload” button to upload a zip file containing your NodeJS application code.
You will be prompted to either upload a local file or a public S3 URL. Choose “Local file” and click the “Upload” button to upload the zip file.
Deploy NodeJS App to Elasticbeanstalk Environment
The Zip file has now been uploaded. We will create the Elasticbeanstalk application now; Click the Create Application button. Elasticbeanstalk will start provisioning the NodeJS application.
After a few minutes, the application should be successfully deployed.
Note: If the application Health status is
Degraded, Navigate to Configuration on the menu and update the Node command to
Scroll down and click Apply. Navigate back to the Dashboard:
The application is now running.
Click on the link highlighted in the top-right corner
Update Application on Elasticbeanstalk
Lets make a quick update to the deployed application.
Go to your favorite IDE and edit the
routes/index.js file. Change the
title property from
Express word to
Express — V2, save it, then zip the files as previously done.
Now that we have zipped the updated application, Navigate to Elasticbeanstalk dashboard and click on the
node-elasticbeanstalk application. Select Application Versions. You will see the initially uploaded zip file.
Click the Upload button to upload a newer version of the application.
Add a Version label, a description, then choose the newly updated zip file for the app, then click Upload.
A new version of the app will now be added to the list of app versions. Elasticbeanstalk lets you choose which version of your application you may want to deploy at anytime. You can also choose to rollback to an earlier version of the app by simply redeploying the source.
Select the new version and click “Deploy”. Elasticbeanstalk will now begin an update process of the application. Wait a few seconds and everything should be ready.
Go back to the browser tab and refresh the page:
We have successfully deployed a new version of the Application.
In this tutorial, we created a fresh NodeJS application and deployed it to AWS Elasticbeanstalk. Lastly, we created and deployed a different version of this application.