0

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);
});
2
  • 3
    Try logging error and response as well and post those here if you still need help. Please also post a link to the request library you are using as it's hard to guess what the callback's signature might be without knowing what library you are using. Commented Mar 23, 2018 at 12:59
  • I tried body and response and the result was undefined on terminal and when I tried error it says operation.uri is a required argument. npmjs.com/package/request I've install request package today so it's updated Commented Mar 23, 2018 at 13:14

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

It feels embarrassing!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.