Weather app with promises
In this section, we'll learn how to use a library that has promises built in. We'll explore the axios library, which is really similar to request. Although, instead of using callbacks as request does, it uses promises. So we don't have to wrap our calls in promises to get that promise functionality. We'll actually be recreating the entire weather app in this section. We'll only have to write about 25 lines of code. We'll go through the entire process: taking the address, getting the coordinates, and then fetching the weather.
Fetching weather app code from the app.js file
To fetch weather app code from the app.js file, we'll duplicate app.js
, because we configure yargs
in the original app.js
file and we'll want to carry the code over to the new project. There's no need to rewrite it. In the weather
directory, we'll duplicate app.js
, giving it a new name, app-promise.js
.
Inside app-promise.js
, before we add anything, let's rip some stuff out. We'll be ripping out the...