Created
June 15, 2018 23:29
-
-
Save mmarchini/eabb1f6afa30625ed11329b4cc504387 to your computer and use it in GitHub Desktop.
Taming the Dragon example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const http = require('http'); | |
const port = 3000; | |
class Visit { | |
constructor(visit_id, headers) { | |
this.visit_id = visit_id; | |
this.headers = headers; | |
} | |
} | |
const visits = new Array(); | |
function saveVisitor(headers) { | |
visits.push(new Visit(visits.length + 1, headers)) | |
} | |
function requestHandler(request, response) { | |
saveVisitor(request.headers); | |
response.end(`Visitor number ${visits.length}\n`); | |
} | |
const server = http.createServer(requestHandler); | |
server.listen(port, (err) => { | |
if (err) return console.log('something bad happened', err); | |
console.log(`server is listening on ${port}. Our PID is: ${process.pid}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment