【问题标题】:How to use request module inside NodeJs routes如何在 NodeJs 路由中使用请求模块
【发布时间】:2017-11-19 20:58:49
【问题描述】:

如何正确使用 app.get('/axe') 中的请求模块。我发现其他问题中只使用了请求模块,但如何触发该功能

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
    }
})
    });
}

【问题讨论】:

    标签: node.js express module request httprequest


    【解决方案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
          }
        })
     });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 2013-01-15
      • 2018-11-08
      • 1970-01-01
      • 2016-01-25
      相关资源
      最近更新 更多