-
-
Save ollym/21c4d53ec77e7862232c to your computer and use it in GitHub Desktop.
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
var http = require('http'); | |
// Instantiate a new server | |
var server = new http.server(); | |
// Bind to port 8080 and address 'localhost' | |
server.bind(8080, 'localhost'); | |
// Listen for incoming connections | |
server.listen(function(request) { | |
// Log the request referrer | |
console.log(request.headers.referrer); | |
// Write some headers | |
request.response.headers['content-type'] = 'text/html'; | |
request.response.write('im writing some data'); | |
request.response.write('and some more data'); | |
// Send the first data to the client | |
request.response.flush(); | |
// Write some more data | |
request.response.write('and some more data'); | |
// This closes and flushes the stream | |
// Headers are sent with the first flush! | |
request.response.send(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment