Welcome aboard! We are happy you are here and wish you good net-raft!
//put this code into app.js
var http = require('http');
var url = require('url');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var q = url.parse(req.url, true);
res.write(q.href);
res.end();
}).listen(3000);
// type "node app.js" in command prompt
// this one parse the url and get json keys latitude and longitude
// this node.js code put into app.js
const request = require('request')
request('http://freegeoip.net/json/' , function(error, res, body) {
var ipuser = JSON.parse(body)
console.log(ipuser.latitude + ", " + ipuser.longitude)
})
// then type "node app.js" in command prompt
The most helpful NODEJS solutions
get user ipNODEJS Click to see more ... 7.6K 1.7K