Deploying a Node.js Application on AWS Elastic Beastalk

RMAG news

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

Sign in to AWS Management Console and navigate to Elastic Beanstalk.
Create a new application and environment, selecting Node.js platform.
Upload your application code (including app.js, package.json, and node_modules if necessary).
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).