diff options
author | Mateja <mail@matejamaric.com> | 2021-05-02 14:31:30 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2021-05-02 14:31:30 +0200 |
commit | 118496bb0d0c5c94773632227707e5116702388a (patch) | |
tree | 08ec5419affa86d15e3fc84fecd9eeaebd1da7b1 | |
parent | d5a7f3cad8ed4cd4ac972c86e4d6364c7731c69d (diff) | |
download | node-playground-118496bb0d0c5c94773632227707e5116702388a.tar.gz node-playground-118496bb0d0c5c94773632227707e5116702388a.zip |
A more verbose version of basic Node.js web server.
-rw-r--r-- | index.js | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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); |