Skip to content
Advertisement

Can I run 2 node.js express using https on 2 specific ports?

I am facing an issue that I am not able to solve alone. I am running 2 node.js server instances on my linux server, but the one running on port 4000 is running well, but the one running on the port 6000 is not working.

See below the example:

Port 4000:

enter image description here

Port 6000:

enter image description here

I checked my port on my server and everything seems to be ok:

enter image description here

See below my code for the 2 instances:

const express = require('express');
const cors = require('cors');
const fs = require('fs');
const https = require('https');

var app = express();
app.use(cors());
app.use(require('body-parser').json());

var privateKey  = fs.readFileSync('/etc/letsencrypt/live/moreapp.com.br/privkey.pem', 'utf8');
var certificate = fs.readFileSync('/etc/letsencrypt/live/moreapp.com.br/fullchain.pem', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var httpsServer = https.createServer(credentials, app);

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

httpsServer.listen(6000, () => {
    console.log("Server Listening");
});

Could you please help to solve this?

Thanks

Advertisement

Answer

I think you should post the complete error for your request. Which http code you get on port 6000 ?

If you call your servers through a firewall, did you correctly authorized requests on that port ?

EDIT : Port 6000 seems to be a forbidden port. He is blocked by many browsers and maybe also by your http tool. Try to change your port and try again.

Source : Chrome ports blocked

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement