Last active
December 30, 2015 20:32
-
-
Save dtolb/4656b23dee6e75302b52 to your computer and use it in GitHub Desktop.
Get forcast.io weather from zip code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require('bluebird'); | |
var zipp = Promise.promisify(require('node-zippopotamus')); | |
var Forecast = require('forecast.io-bluebird'); | |
var forecast = new Forecast({ | |
key: 'PUT_YOUR_FORECAST.IO_KEY_HERE', //PUT YOUR FORECAST.IO KEY HERE, | |
timeout: 2500 | |
}); | |
var getWeather = function (zipCode){ | |
return zipp('us', zipCode) | |
.then(function (data) { | |
var coords = { | |
"latitude": data.places[0].latitude, | |
"longitude": data.places[0].longitude | |
} | |
return forecast.fetch(coords.latitude, coords.longitude); | |
}); | |
}; | |
getWeather('90210') | |
.then(function(weather) { | |
console.log(weather); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment