Inside our app-promise file, we can get started by loading in axios at the top. We'll make a constant called axios, setting it equal to require('axios'), as shown here:
const yargs = require('yargs');
const axios = require('axios');
Now that we have this in place, we can actually start making the calls in the code. This will involve us pulling out some of the functionality from the geocode and weather files. So we'll open up the geocode.js and weather.js files. Because we will be pulling some of the code from these files, things such as the URL and some of the error handling techniques. Although we'll talk about the differences as they come up.
The first thing we need to do is to encode the address and get the geocode URL. Now this stuff happens inside geocode.js. So we'll actually copy the encodedAddress variable line, where we create the encoded address, and paste it in the app-promise file, following the argv variable:
.argv;
var encodedAddress = encodeURIComponent(argv.address);
Now we do need to tweak this a little bit. The address variable doesn't exist; but we have argv.address. So, we'll switch address with argv.address:
var encodeAddress = encodeURIComponent(argv.address);
Now we have the encoded address; the next thing we need to get before we can start using axios is the URL that we want to make the request to. We'll grab that from the geocode.js file as well. In app-promise.js, we will make a new variable called geocodeURI. Then, we'll take the URL present in geocode.js, from the opening tick to the closing tick, copy it, and paste it in app-promise.js, equal to geocodeURI:
var encodedAddress = encodeURIComponent(argv.address);
var geocodeUrl = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}`;
Now we use the encoded address variable inside the URL; this is fine because it does exist in our code. So at this point, we have our geocodeUrl variable and we can get started in making our very first axios request.