Skip to content

Instantly share code, notes, and snippets.

@Aaronontheweb
Created January 28, 2012 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Aaronontheweb/1692104 to your computer and use it in GitHub Desktop.
Save Aaronontheweb/1692104 to your computer and use it in GitHub Desktop.
Node.JS: Hello World w/ IP Address
/* 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);
@tempiltin
Copy link

khg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment