Use http.get in node to get data. Why can't export export it? How to export the obtained data

the approximate code is as follows:

let http = require("https")
let obj ;
//get 
http.get("https://c.y.qq.com/",function(req,res){
let html="";
req.on("data",data =>{
    html+=data;
    //console.log(data);
});
req.on("end",() => {
    //obj = eval ("(" + html + ")");
     obj = JSON.parse(html);
    //console.log(obj);
    export {obj}
});
});

data can be exported by console.log, but data cannot be exported by export.


export can only be on the outermost layer.

let dd=null
req.on ('end', () = > {

)
//obj = eval ("(" + html + ")");
 obj = JSON.parse(html);
//console.log(obj);
dd=obj

});
});

export {dd}


Export
with a promise package. In addition, export is the syntax of es6 . I don't know if you handled it

.
let https = require('https');
// 
var p = new Promise(function(resolve) {
  https.get('https://c.y.qq.com/',function(req,res){
        let html='';
        req.on('data',data =>{
            html+=data;
        });
        req.on('end',() => {
            resolve(JSON.parse(html))
        });
    });
});
export {p}

Asynchronous with Synchronize?

Menu