Now in order to play around with the weather API, we'll take the exact same URL we have defined in the previous section, and we'll make a request in app.js. First, we want to do a little setup work.
Inside of app.js, we'll comment out everything we have so far, and next to our API key we'll make a call to request, requesting this exact URL, just like we did for the geocode API in the previous section/chapter, before we made it dynamic. Then we'll print out the body.currently.temperature property to the screen, so when we run the app we'll see the current temperature for whatever latitude and longitude we used. In our case it's a static latitude and longitude representing Philadelphia.
In order to get started we'll load in request. Now we had it in the app.js file before and then we removed it in the previous section, but we'll add it back once again. We'll add it next to the commented out code, by creating a constant called request, and loading it in, const request equals to require('request'):
const request = require('request');
Now we can go ahead and make the actual request, just like we did for the geocode API by calling request, it's a function just like this:
const request = require('request');
request();
We have to pass in our two arguments, the options object is the first one, and the second one is the arrow function:
request({}, () => {
});
This is our callback function that gets fired once the HTTP request finishes. Before we fill out the actual function, we want to set up our options. There're two options, URL and JSON. We'll set url equal to the static string, the exact URL we have in the browser:
request({
url: 'https://api.forecast.io/forecast/4a04d1c42fd9d32c97a2c291a32d5e2d/39.9396284,-75.18663959999999',
}, () => {
Then in the next line after comma, we can set json equal to true, telling the request library to go ahead and parse that body as JSON, which it is:
request({
url: 'https://api.forecast.io/forecast/4a04d1c42fd9d32c97a2c291a32d5e2d/39.9396284,-75.18663959999999',
json: true
}, () => {
From here, we can go ahead and add our callback arguments; error, response, and body. These are the exact same three arguments we have in the if block of geocode.js file for the geocoding request:
request({
url: 'https://api.forecast.io/forecast/4a04d1c42fd9d32c97a2c291a32d5e2d/39.9396284,-75.18663959999999',
json: true
}, (error, response, body) => {
});
Now that we have this in place, the last thing we need to do is print the current temperature, which is available on the body using console.log statement. We'll use console.log to print body.currently.temperature, as shown here:
request({
url: 'https://api.forecast.io/forecast/4a04d1c42fd9d32c97a2c291a32d5e2d/39.9396284,-75.18663959999999',
json: true
}, (error, response, body) => {
console.log(body.currently.temperature);
});
Now that we have the temperature printing, we need to test it by running it from the Terminal. In the Terminal, we'll rerun the previous command. The address is not actually being used here since we commented out that code, and what we get is 28.65, as shown in this code output:

With this we have our weather API call working inside of the application.