2017-11-19 18 views
-1

app.get( '/ ax')内のリクエストモジュールを正しく使用する方法。私は他の質問で唯一の要求モジュールの使用方法を見つけるが、どのように関数にNodeJsルート内でリクエストモジュールを使用する方法

var request = require("request") 

var url = "https://www.lonelyplanet.com/usa/san-francisco/attractions/de-young-museum/a/poi-sig/1340028/1329646"; 

module.exports = app => { 
    app.get('/axe', (req, res, next) => { 
req.request({ 
    url: url, 
    json: true 
}, function (error, response, body) { 

    if (!error && response.statusCode === 200) { 
     console.log(body) // Print the json response 
    } 
}) 
    }); 
} 

答えて

1

をトリガするような単純な:

app.get('/axe', (req, res, next) => { 
    request.get(url, function (error, response, body) {  
     if (!error && response.statusCode === 200) { 
     console.log(body) // Print the json response 
     } 
    }) 
}); 
関連する問題