Reputation: 45
Here I am learning about Callback functions and API to make weather app on node but when I am running the app on Terminal it says undefined I don't know why?
const request = require("request");
request({
URL: "http://maps.googleapis.com/maps/api/geocode/json?address=1301%20lombard%20street%20philadelphia",
json: true
}, (error, response, body) => {
console.log(body);
});
Upvotes: 0
Views: 41
Reputation: 2376
You are calling request
incorrectly. You need to call it like so:
request("http://maps.googleapis.com/maps/api/geocode/json?address=1301%20lombard%20street%20philadelphia", {
json: true
}, (error, response, body) => {
console.log(body);
});
alternatively
request({
url: "http://maps.googleapis.com/maps/api/geocode/json?address=1301%20lombard%20street%20philadelphia",
json: true
}, (error, response, body) => {
console.log(body);
});
Notice the url
property in lowercase, whereas yours was uppercase
Refer to https://github.com/request/request#requestoptions-callback
Upvotes: 1