aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-05-02 14:31:30 +0200
committerMateja <mail@matejamaric.com>2021-05-02 14:31:30 +0200
commit118496bb0d0c5c94773632227707e5116702388a (patch)
tree08ec5419affa86d15e3fc84fecd9eeaebd1da7b1
parentd5a7f3cad8ed4cd4ac972c86e4d6364c7731c69d (diff)
downloadnode-playground-118496bb0d0c5c94773632227707e5116702388a.tar.gz
node-playground-118496bb0d0c5c94773632227707e5116702388a.zip
A more verbose version of basic Node.js web server.
-rw-r--r--index.js9
1 files 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('<h1>lol</h1>');
+};
-}).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);