Created
January 28, 2012 02:07
-
-
Save Aaronontheweb/1692104 to your computer and use it in GitHub Desktop.
Node.JS: Hello World w/ IP Address
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
/* Basic HelloWorld Node.JS example */ | |
var http = require('http'); | |
//Node function called each time our event loop receives a new HTTP request | |
function onRequest(req, res){ | |
res.writeHead(200, {'Content-Type':'text/plain'}); | |
res.end('Hello ' + req.connection.remoteAddress + '!'); | |
/* Write the IP addresses of our connecting client to console */ | |
console.log('Incoming connection from ' + req.connection.remoteAddress); | |
} | |
//Listen for connections on the port provided to us by the host process | |
var server = http.createServer(onRequest).listen(process.env.PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
khg