I'm trying to run 2 instances of NodeJS on the same port and server from diffrent server.js
files (diffrent dir, config etc). My server provider gave me an information that vhost
is running for a diffrent domain, and there is the question. How to handle it in NodeJS Express app ? I've tried to use vhost
from https://github.com/expressjs/vhost like that :
const app = express();
const vhost = require('vhost');
app.use(vhost('example1.org', app));
// Start up the Node server
app.listen(4100, () => {
console.log(`Node server listening on 4100`);
});
And for second application like that:
const app = express();
const vhost = require('vhost');
app.use(vhost('example2.org', app));
// Start up the Node server
app.listen(4100, () => {
console.log(`Node server listening on 4100`);
});
But when I'm trying to run second instance I'm getting EADDRINUSE ::: 4100
, so vhost doesn't work here.
Do you know how to fix it ?