skip to Main Content

I have deployed NodeJS app on AWS Beanstalk. I am using AWS code pipeline for deployment from Github. After deployment when I am visiting URL, it’s showing below error on web page:

502 Bad Gateway
nginx/1.18.0

Below is my basic node code:

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

const port = 3000 || process.env.PORT;

   app.get('/',(req,res) => {

   res.send("Hello there");
});

app.listen(port,(req,res) => {

 console.log(`App is running at ${port}`);
});

In below screen health of my environment is also showing severe. How can I resolve this?

i

2

Answers


  1. Your load balancer needs a part of your application to "ping" which is sometimes called a heart beat or just a ‘health check’.

    This is usually just something that returns a HTTP 200 response to let the load balancer know that the host is healthy and can receive traffic.

    I’m not a node.js guy but if you can create some endpoints like /health-check and just return an "ok" or HTTP 200 that will satisfy the need.

    You can also have your health-check do something like check if the database connection is running as well. It’s up to your specific use case.

    Within beanstalk you would then designate /health-check as the URL endpoint for the load balancer to check.

    Check out this link as well:
    https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.healthstatus.html

    Login or Signup to reply.
  2. This is the logic error => const port = 3000 || process.env.PORT;

    Try with this assignment => const port = process.env.PORT || 3000;

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search