Skip to content

Instantly share code, notes, and snippets.

@dtolb
Last active December 30, 2015 20:32
Show Gist options
  • Save dtolb/4656b23dee6e75302b52 to your computer and use it in GitHub Desktop.
Save dtolb/4656b23dee6e75302b52 to your computer and use it in GitHub Desktop.
Get forcast.io weather from zip code
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