9951 explained code solutions for 126 technologies


nodejsHTTP server listen on multiple ports


const http = require('http');

[81,82,83].forEach(function(p) {
  let server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.end('Hi');
  });
  
  server.listen(p);
})ctrl + c
require('http')

import module to work with http protocol

http.createServer

creates HTTP server

(req,

object with request data

res

object to manage response

.end(

finished http response with given content

server.listen

launch server on a given port and hostname

[81,82,83]

array of ports to listen server on