Skip to content

Instantly share code, notes, and snippets.

@akoenig
Created March 4, 2012 18:04
Show Gist options
  • Save akoenig/1974181 to your computer and use it in GitHub Desktop.
Save akoenig/1974181 to your computer and use it in GitHub Desktop.
node.js talk - http server
/*
* Small HTTP server with node.js
*
* Author: André König (andre.koenig@gmail.com)
*
*/
"use strict";
var http = require('http');
var dns = require('dns');
var port = 8080;
http.createServer(function (req, res) {
var domain = 'gtugs.org';
dns.resolve(domain, function (err, addresses) {
var answer = {
dnsResolve: {
domain: domain,
addresses: addresses
}
};
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end(JSON.stringify(answer));
});
}).listen(port);
console.log('A http server which is listening on port ' + port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment