Get URL Contents in Node.js with Express

前端 未结 3 1521
暖寄归人
暖寄归人 2020-12-25 15:19

How would I go about downloading the contents of a URL in Node when using the Express framework? Basically, I need to complete the Facebook authentication flow, but I can\'t

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 15:42

    Using http way requires way more lines of code for just a simple html page .

    Here's an efficient way : Use request

    var request = require("request");
    
    request({uri: "http://www.sitepoint.com"}, 
        function(error, response, body) {
        console.log(body);
      });
    });
    

    Here is the doc for request : https://github.com/request/request



    2nd Method using fetch with promises :

        fetch('https://sitepoint.com')
        .then(resp=> resp.text()).then(body => console.log(body)) ; 
    

提交回复
热议问题