Created
March 4, 2012 18:04
-
-
Save akoenig/1974181 to your computer and use it in GitHub Desktop.
node.js talk - http server
This file contains hidden or 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
/* | |
* Small HTTP server with node.js | |
* | |
* Author: André König ([email protected]) | |
* | |
*/ | |
"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