Now that we have this in place, we can go ahead and move into app.js to add some code. The first thing we need do is remove the API key. We no longer need that. And we'll highlight all of the commented code and uncomment it using the command /.
Now we'll import the weather.js file. We'll create a const variable called weather, and setting it equal to the require, return result:
const yargs = require('yargs');
const geocode = require('./geocode/geocode');
const weather = require('');
In this case we're requiring our brand new file we just created. We'll provide a relative path ./ because we're loading in a file that we wrote. Then we'll provide the directory named weather followed by the file named weather.js. And we can leave off that js extension, as we already know:
const weather = require('./weather/weather');
Now that we have the Weather API loaded in, we can go ahead and call it. We'll comment out our call to geocodeAddress and, we'll run weather.getWeather():
// geocode.geocodeAddress(argv.address, (errorMessage, results) => {
// if (errorMessage) {
// console.log(errorMessage);
// } else {
// console.log(JSON.stringify(results, undefined, 2));
// }
//});
weather.getWeather();
Now as I mentioned before, there will be arguments later in the section. For now we'll leave them empty. And we can run our file from the Terminal. This means we should see the weather printing for the coordinates, we hard-coded in the previous section. So, we'll run node app.js. We'll need to provide an address since we haven't commented out the yargs code. So we'll add a dummy address. I'll use a zip code in New Jersey:
node app.js -a 08822

Now, the geolocation code is never running, because that is commented out. But we are running the weather code that got moved to the new file. And we are indeed seeing a temperature 31.82 degrees, which means that the code is properly getting executed in the new file.