How to get data out of a Node.js http get request

后端 未结 7 1188
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 23:25

I\'m trying to get my function to return the http get request, however, whatever I do it seems to get lost in the ?scope?. I\'m quit new to Node.js so any help would be appr

相关标签:
7条回答
  • 2020-11-28 23:54

    Shorter example using http.get:

    require('http').get('http://httpbin.org/ip', (res) => {
        res.setEncoding('utf8');
        res.on('data', function (body) {
            console.log(body);
        });
    });
    
    0 讨论(0)
提交回复
热议问题