Skip to content

Instantly share code, notes, and snippets.

@edwinclement08
Created October 14, 2021 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwinclement08/9a9f0776629e093e0cb993eba9be63f6 to your computer and use it in GitHub Desktop.
Save edwinclement08/9a9f0776629e093e0cb993eba9be63f6 to your computer and use it in GitHub Desktop.
node-server-get-client-ip.js
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello ' + req.connection.remoteAddress + '!');
// Client address in request -----^
});
server.on('connection', function(sock) {
console.log('Client connected from ' + sock.remoteAddress);
// Client address at time of connection ----^
});
server.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment