I was reading about clusters in Node js i came across with a simple example, whereas the main file creates four childs processes and each of them listens to 8080 port.
The code runs well but i dont get:
How its possible to have multiple child processes to listen to the same port?
I was expecting to get a message like
Error: listen EADDRINUSE: address already in use :::8080
const cluster = require("cluster");
if (cluster.isMaster) {
for (let i = 0; i <= 4; i++) cluster.fork();
} else {
require("./test.js");
}
test.js
const http1 = require("http");
http1
.createServer((req, res) => {
console.log("request1");
res.write("hello1");
res.end();
})
.listen(8080, () => {
console.log("begin");
});