DEV Community

Deploying a Node.js Application on AWS Elastic Beastalk

Deploying applications to AWS Elastic Beanstalk is straightforward and ideal for quickly deploying Node.js applications without managing infrastructure.
We'll deploy a basic Node.js application using Express.js to AWS Elastic Beanstalk.

Example Application

Setup Your Project

mkdir nodejs-app
cd nodejs-app
npm init -y

Enter fullscreen mode Exit fullscreen mode

Install Dependencies

npm install express

Enter fullscreen mode Exit fullscreen mode

Create The Application

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Welcome to AWS Elastic Beanstalk Deployment!');
});

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

Enter fullscreen mode Exit fullscreen mode

Create .ebextensions Directory

option_settings:
  aws:elasticbeanstalk:container:nodejs:
    NodeCommand: "app.js"
Enter fullscreen mode Exit fullscreen mode

Deploy to AWS Elastic Beanstalk

  1. Sign in to AWS Management Console and navigate to Elastic Beanstalk.
  2. Create a new application and environment, selecting Node.js platform.
  3. Upload your application code (including app.js, package.json, and node_modules if necessary).
  4. Deploy your application.

Access Your Application
Once deployed, Elastic Beanstalk will provide you with a URL to access your application (http://app-name.elasticbeanstalk.com).

Top comments (0)