udemy-node-weather-app/weather/weather.js

24 lines
589 B
JavaScript
Raw Permalink Normal View History

2017-11-21 05:34:29 +00:00
const request = require('request');
const API_KEY = "ae8dd4c9c3a690289fd7cfe125f50e84"
var getWeather = (latitude, longitude, callback) => {
request({
url: `https://api.darksky.net/forecast/${API_KEY}/${latitude},${longitude}`,
json: true
}, (error, response, body) => {
if (!error && response.statusCode === 200){
callback(undefined, {
temperature: body.currently.temperature,
apparentTemperature: body.currently.apparentTemperature
});
} else {
callback("Unable to fetch weather");
}
});
}
module.exports = {
getWeather
}