Skip to content

Instantly share code, notes, and snippets.

@mmarchini
Created June 15, 2018 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmarchini/eabb1f6afa30625ed11329b4cc504387 to your computer and use it in GitHub Desktop.
Save mmarchini/eabb1f6afa30625ed11329b4cc504387 to your computer and use it in GitHub Desktop.
Taming the Dragon example
'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