Skip to content

Instantly share code, notes, and snippets.

@jonatw
Last active December 10, 2015 17:28
Show Gist options
  • Save jonatw/4468299 to your computer and use it in GitHub Desktop.
Save jonatw/4468299 to your computer and use it in GitHub Desktop.
nodejs practice #1 with native http object
// this practice is base on this documents http://nodejs.org/api/http.html#http_request_connection
var server,
ip = "192.168.1.12",
port = 1337,
http = require('http');
server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
console.log("========== syslog ========== \n"+req.method+"\n"+req.url+"\n");
// debug headers
for( var header_data_index in req.headers){
console.log("http header #"+header_data_index+" : "+req.headers[header_data_index]+"\n");
}
//debug trailser
for( var trailer_data_index in req.trailers){
console.log("http trailer #"+trailer_data_index+" : "+req.trailers[trailer_data_index]+"\n");
}
console.log("httpVersionMajo : "+req.httpVersionMajo+"\n");
//debug connection
for( var connection_data_index in req.connection){
console.log("http connection #"+connection_data_index+" : "+req.connection[connection_data_index]+"\n");
}
});
server.listen(port, ip);
console.log("Server running at http://" + ip + ":" + port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment