Digvijay
Digvijay

Reputation: 3271

Node app is not reachable on EC2 insrance

I have deployed simple nodejs application on EC2 instance and modified all inbound rules to made port publicly accessible but even after that I am unable to access application.

below is my app:

server.js

const express = require('express');
const log = require('./logger');

const app = express();

app.get('/',(req,res) => {
 
    res.send("Happy logger");
 
 });

app.listen(2000,() => console.log("App is  listening"));     

Below is my inbound rules settings enter image description here

When I am hitting on ec2-3-82-196-99.compute-1.amazonaws.com:2000 url its showing below error.

enter image description here

Someone let me know what I am doing wrong.

Upvotes: 0

Views: 765

Answers (2)

K Teja
K Teja

Reputation: 1

I am also having the same problem here.

I tried both HTTP and HTTPS, but no use. The app is working in the localhost (A windows 2022 server).

URLS:

https://ec2-3-110-102-41.ap-south-1.compute.amazonaws.com:8080

http://ec2-3-110-102-41.ap-south-1.compute.amazonaws.com:8080

Security Inbound Rules: Inbound Rules

NodeJS Code:

const express = require("express");
const cors = require("cors");

const dotenv = require('dotenv')
dotenv.config();

const app = express();

app.use(cors({
    origin: "*"
}));

app.use(express.json());
app.use(express.urlencoded({ extended: true }));


app.get("/", (req, res) => {
    res.json({ message: "Hello" });
});

const PORT = process.env.PORT || 8080;

app.listen(PORT, '0.0.0.0', () => {
    console.log("Server listening on port::::::::::::::::::::::\n", PORT);
});

Upvotes: 0

Winson Tanputraman
Winson Tanputraman

Reputation: 3574

From your screenshot, you are accessing HTTPS in Chrome:

https://ec2-3-82-196-99.compute-1.amazonaws.com:2000.

As the commenter suggested, should use HTTP instead (make sure you see the 'Not secure' sign):

http://ec2-3-82-196-99.compute-1.amazonaws.com:2000

enter image description here

Upvotes: 2

Related Questions