Deploying a Node.js Application on AWS Elastic Beastalk



This content originally appeared on DEV Community and was authored by FABIOLA ESTEFANI POMA MACHICADO

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

Install Dependencies

npm install express

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}`);
});

Create .ebextensions Directory

option_settings:
  aws:elasticbeanstalk:container:nodejs:
    NodeCommand: "app.js"

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).


This content originally appeared on DEV Community and was authored by FABIOLA ESTEFANI POMA MACHICADO