The http module allows us to perform tasks in relation to the HTTP protocol. The following code snippet showcases how we can use the http module to implement very minimal implantation of a web server:
import * as http from "http"; const hostname = "127.0.0.1"; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader("Content-Types", "text/plain"); res.end("Hello world!"); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); });
We have created a web server that will listen to all the HTTP requests. The http module allows us to implement our web HTTP server, but its level of abstraction is very low. In a real-world application, ...