user3276247
user3276247

Reputation: 1084

Custom Port not working for node.js app on AWS EC2 instance

I have deployed the following code on my AWS EC2 instance -

const express = require('express')
const app = express()
app.get('/test',(req,res) => {res.send('Hi')})

app.listen(3001, () => console.log('Server running on port 80'))

When I try to visit the following url - http://ec2-13-59-209-0.us-east-2.compute.amazonaws.com/test , I get connection refused message. The message on the UI is ec2-13-59-209-0.us-east-2.compute.amazonaws.com refused to connect.

I did go through the documentation and set up security group to listen on port 3001. But that did not help either.So I enabled on traffic for all the ports. Still I was not able to connect. Please find below snapshot of the security group. It would be great if you can help me with this.

enter image description here

Upvotes: 4

Views: 2514

Answers (1)

Mark B
Mark B

Reputation: 200562

You need to tell Express to listen to all traffic, not just localhost traffic. Change your app.listen line to:

app.listen(3001, "0.0.0.0");

Upvotes: 4

Related Questions