How does node return asynchronously acquired data?

  node.js, question

You need to write a function that captures data from another web page simultaneously and displays it to the user.

The problem arises, because it is a separate module for capturing web pages, and the use of. get () in the module is asynchronous acquisition, but I cannot directly return the value when on(‘end’), because it only returns the value of the method in. get.

How should this problem be solved?

module.exports = function(callback){
var req = http.request({
    hostname:'top.baidu.com',
    port:80,
    path:'/category?c=10&fr=topindex',
    method:'GET',
    header:{}
},function(response){
    //也是一个流对象
    console.log(response.statusCode);
    console.log(response.headers);
    var bufs = [];
    response.on('data',function(data){
        bufs.push(data);
    })
    response.on('end',function(){
        var buffer = Buffer.concat(bufs);
        var result = iconv.decode(buffer,'gbk');
        var reg = /<a.加?<\/a>/g;
        var categories = result.match(reg);
        categories = categories.filter(function(category){
            return category.includes('buzz');
        });
        callback(categories);
    });
});
req.write('请求体');
//当调用end的时候请求才会真正发出
req.end();
}
Is that what it means? nodejs is used to grab data from other websites and return it to its client side.
 Using http's request, the first parameter is the configuration item, the second is the callback function that successfully requested, then we can listen to the data in the response body.  .