I can't understand Why I can only connect to 8080 port in node Js express server

356 Views Asked by At
const express = require('express');

const app = express();
app.set('port', process.env.PORT || '3000');

app.get('/', (req,res)=>{
    res.send('Hello Express');
});

app.listen(app.get('port'),()=>{
    console.log(app.get('port'),'listening');
})

Hi, I started studying nodeJs but got a problem.

If I run the server this way,

$ node app.js
8080 Listening

There's no problem in connecting to this server.

However, I got a problem if I run the server after changing the port.

$ PORT=3001  node app.js                                                                                                                                                                                   
3001 Listening

It seems working without problem but I can't connect to 3001 port. So I tried other ports but neither worked. I can't understand why only 8080 port is available.

I'm developing by using AWS cloud9 IDE and Ubuntu 18.04.5 LTS.

0

There are 0 best solutions below