1
var http = require("https");
var options = {
"method": "GET",
"hostname": "freegeoip.app",
"port": null,
"path": "/json/",
"headers": {
"accept": "application/json",
"content-type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
This code seems to be back-end, in Node.js, I don’t see how this could go on the front-end, since it’s not made for this, it’s important you [Edit] your question avoiding images to demonstrate codes for a number of great reasons and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve it. To better enjoy the site, understand and avoid closures is worth reading the Stack Overflow Survival Guide in English.
– Guilherme Nascimento