Created
June 20, 2017 12:41
-
-
Save bmorelli25/8b03c50b913796a42a10a8996971ab2c to your computer and use it in GitHub Desktop.
node.js weather app
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
| const request = require('request'); | |
| const argv = require('yargs').argv; | |
| let apiKey = '*****************************'; | |
| let city = argv.c || 'portland'; | |
| let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&units=imperial&appid=${apiKey}` | |
| request(url, function (err, response, body) { | |
| if(err){ | |
| console.log('error:', error); | |
| } else { | |
| let weather = JSON.parse(body) | |
| let message = `It's ${weather.main.temp} degrees in ${weather.name}!`; | |
| console.log(message); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment