Skip to content

Instantly share code, notes, and snippets.

@ollym
Created June 28, 2010 22:26
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 ollym/21c4d53ec77e7862232c to your computer and use it in GitHub Desktop.
Save ollym/21c4d53ec77e7862232c to your computer and use it in GitHub Desktop.
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