Created
October 14, 2021 14:38
-
-
Save edwinclement08/9a9f0776629e093e0cb993eba9be63f6 to your computer and use it in GitHub Desktop.
node-server-get-client-ip.js
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
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