在这里,我正在学习回调函数和API,以便在节点上制作天气应用程序但是当我在终端上运行应用程序时,它说未定义我不知道为什么?
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);
});
答案 0 :(得分:1)
您正在正确呼叫request
。你需要这样称呼它:
request("http://maps.googleapis.com/maps/api/geocode/json?address=1301%20lombard%20street%20philadelphia", {
json: true
}, (error, response, body) => {
console.log(body);
});
<强>替代地强>
request({
url: "http://maps.googleapis.com/maps/api/geocode/json?address=1301%20lombard%20street%20philadelphia",
json: true
}, (error, response, body) => {
console.log(body);
});
请注意url
属性为小写,而您的属性为大写
请参阅https://github.com/request/request#requestoptions-callback