Last active
May 28, 2018 18:41
-
-
Save maisonm/29ae56280265562818380e57ad4f1308 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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