How to Deploy a Node.js App to AWS Elastic Beanstalk

AWS
EmpowerCodes
Oct 30, 2025

Deploying Node.js applications on AWS can be challenging if you are new to cloud platforms. AWS Elastic Beanstalk simplifies this by automatically handling provisioning, load balancing, autoscaling, and application monitoring. It allows developers to focus on code while AWS manages the infrastructure.

In this guide, you will learn how to deploy a Node.js application to AWS Elastic Beanstalk step-by-step, from setting up your environment to verifying your deployment.

What is AWS Elastic Beanstalk?

AWS Elastic Beanstalk is a Platform-as-a-Service (PaaS) offering from Amazon Web Services that enables fast application deployment without managing underlying servers.

Key Benefits

  • Automated deployment and scaling

  • Built-in monitoring and logging

  • Supports multiple environments (dev, staging, production)

  • Built-in integration with EC2, RDS, S3, and CloudWatch

Prerequisites

Before you start, ensure the following are installed:

  • Node.js and npm

  • AWS Account

  • AWS CLI

  • Elastic Beanstalk CLI (EB CLI)

  • Git (optional but recommended)

Step 1: Prepare Your Node.js Application

Create a basic Node.js app or use an existing one. Ensure you include a file named package.json with required dependencies.

A sample app.js might look like this:

const express = require("express"); const app = express(); app.get("/", (req, res) => { res.send("Hello from Elastic Beanstalk"); }); const port = process.env.PORT || 3000; app.listen(port, () => console.log(`Server running on port ${port}`));

Important: Elastic Beanstalk uses the environment-provided PORT variable. Do not hardcode a port.

Step 2: Install and Configure AWS CLI

Install AWS CLI and configure it with your account credentials.

Run:

aws configure

Provide the following:

  • AWS Access Key ID

  • AWS Secret Access Key

  • Default region (example: us-east-1)

  • Output format (json recommended)

Step 3: Install the EB CLI

The EB CLI helps you manage Elastic Beanstalk environments using the command line.

Install using pip:

pip install awsebcli

Verify installation:

eb --version

Step 4: Initialize Elastic Beanstalk

Navigate to your Node.js project directory and run:

eb init

You will be prompted to:

  • Select the AWS region

  • Select the application name

  • Choose the platform (select Node.js)

  • Set up SSH access (optional but recommended for debugging)

Step 5: Create an Environment and Deploy

To create a new environment:

eb create node-env

This step configures the environment with EC2, Load Balancer, and security group.

Once created, deploy your app:

eb deploy

Elastic Beanstalk zips your project and uploads it. After a few minutes, AWS will provision resources and deploy your application.

Step 6: Verify Deployment

Run the following to open the app in your browser:

eb open

You should see your application running on an Elastic Beanstalk domain like:

http://node-env.eba-xyz123.us-east-1.elasticbeanstalk.com

Step 7: Environment Configuration and Variables

To configure environment variables, run:

eb setenv NODE_ENV=production API_KEY=yourapikey

Or configure them via the AWS Console under Configuration > Software.

Step 8: View Logs and Monitor

To see logs:

eb logs

Elastic Beanstalk integrates with CloudWatch for monitoring, allowing you to track:

  • CPU usage

  • Latency

  • Request counts

  • Errors

Step 9: Updating Your Application

After making code changes, simply redeploy:

eb deploy

Elastic Beanstalk supports zero-downtime deployments using rolling updates.

Step 10: Cleanup (Optional)

To avoid charges when the environment is no longer needed:

eb terminate node-env

This deletes all associated AWS resources to prevent billing.

Best Practices for Node.js on Elastic Beanstalk

Best PracticeBenefit
Use environment variables, not hard-coded valuesBetter security and portability
Enable load balancing for productionHigh availability
Use RDS in a separate environmentData persistence
Use ebextensions for custom configBetter lifecycle management
Enable auto-healingImproves reliability

Conclusion

AWS Elastic Beanstalk is a powerful platform for deploying and managing Node.js applications without worrying about servers or scaling. By following these steps, you can quickly set up your application, deploy changes, and manage environments with ease.

Whether you're deploying a small app or a large enterprise solution, Elastic Beanstalk provides the automation and reliability needed to run Node.js workloads in the cloud efficiently.