From 118496bb0d0c5c94773632227707e5116702388a Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 2 May 2021 14:31:30 +0200 Subject: A more verbose version of basic Node.js web server. --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6ea86da..5e753e1 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,13 @@ const http = require('http'); -http.createServer((req, res) => { +const requestHandler = (req, res) => { + console.log(`${req.method} ${req.url}`); res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'}); res.end('

lol

'); +}; -}).listen(8080, () => console.log('Server started on port 8080.')); +const onServerStart = () => console.log('Server started on port 8080.'); + +const server = http.createServer(requestHandler); +server.listen(8080, onServerStart); -- cgit v1.2.3