Skip to content

Instantly share code, notes, and snippets.

@shershen08
Created January 7, 2017 22:05
Show Gist options
  • Save shershen08/d664ce3674cf1c655430864deab01df0 to your computer and use it in GitHub Desktop.
Save shershen08/d664ce3674cf1c655430864deab01df0 to your computer and use it in GitHub Desktop.
Weather forecast from IP recipe
const request = require('request');
const APIKEY = require('./weather_apikey'); //file with '{"key": "XXX"}'
const ip = '208.67.222.222';
const getLatLng = (ip) => {
const url = `https://ipapi.co/${ip}/latlong/`;
request.get(url)
.on('response', function (response) {
if (response.statusCode == 200) getWeather(response.body);
});
}
const getWeather = (latLngArray) => {
const url = `http://api.openweathermap.org/data/2.5/weather?lat=
${latLngArray[0]}&lon=${latLngArray[1]}&appid=${API_KEY.key}`;
request.get(url)
.on('response', function (response) {
if (response.statusCode == 200) console.log(response.body);
});
}
getLatLng(ip);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment