Skip to content

Instantly share code, notes, and snippets.

@maisonm
Last active May 28, 2018 18:41
Show Gist options
  • Save maisonm/29ae56280265562818380e57ad4f1308 to your computer and use it in GitHub Desktop.
Save maisonm/29ae56280265562818380e57ad4f1308 to your computer and use it in GitHub Desktop.
app.get('/search-location-weather', (req, res) => {
//build api URL with user zip
const baseUrl = 'http://api.openweathermap.org/data/2.5/weather?zip=';
const apiId = '&appid=<YOUR API KEY GOES HERE>&units=imperial';
const userLocation = (url1, url2, zipcode) => {
let newUrl = url1 + zipcode + url2;
return newUrl;
};
const apiUrl = userLocation(baseUrl, apiId, zipcode);
fetch(apiUrl)
.then(res => res.json())
.then(data => {
res.send({ data });
})
.catch(err => {
res.redirect('/error');
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment