Answer the question
In order to leave comments, you need to log in
Why is node.js missing a function?
This code returns the necessary information to the browser, but it takes a long time - 2-4 seconds.
var rp = require('request-promise');
var i = '91.105.236.7';
app.get('/', function(req, res){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
var options = {
uri: 'http://api.ipapi.com/' + i,
qs: {
access_key: '98eeeb1c1233456743840f9195d' // -> uri + '?access_token=xxxxx%20xxxxx'
}
};
rp(options)
.then(function (repos) {
console.log(repos);
res.send(repos);
})
.catch(function (err) {
// API call failed...
});
});
var rp = require('request-promise');
var i = '91.105.236.7';
var geo = geoIP(i);
app.get('/', function(req, res){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.send(geo);
});
function geoIP(i){
var options = {
uri: 'http://api.ipapi.com/' + i,
qs: {
access_key: '98eeeb1c73191023211233121233840f9195d' // -> uri + '?access_token=xxxxx%20xxxxx'
}
};
rp(options)
.then(function (repos) {
console.log(repos);
return repos
})
.catch(function (err) {
// API call failed...
});
}
app.get('/', function(req, res){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
var geo = geoIP(i);
res.send(geo);
});
Answer the question
In order to leave comments, you need to log in
so your geoIP function does not return anything, and the output to the console does not depend on the request at all
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question