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

后端 未结 7 1217
没有蜡笔的小新
没有蜡笔的小新 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:38

    from learnyounode:

    var http = require('http')
    var bl = require('bl')
    
    http.get(process.argv[2], function (response) {
        response.pipe(bl(function (err, data) {
            if (err)
                return console.error(err)
            data = data.toString()
            console.log(data)
        }))
    })
    

提交回复
热议问题