fscreateReadStream
router.post("/", function(req, res, next) {
var readStream = fs.createReadStream("./public/javascripts/Json.json");
var data = "";
readStream.on("data",(chunk)=>{
data = data+chunk;
})
readStream.on("end",()=>{
var tmp = JSON.parse(data);
res.send(tmp);
})
});
Json.json
/*{
"head":{
"resolution":"600x100"
},
"data":{
"info":"wangergou"
}
}*/
gitBash
< hr >
access to createReadStream documents has autoClose:false; as a treasure, but failed to use it.
how can comments be read and sent to the front end? Or read uncommented code snippets directly, bypassing comments?
< hr > under the adopted QQ, the positioning problem is that json.parse (), encounters / * comments, which is consistent with the fact that json itself does not allow comments.
all I have to do is break the rules of json, so I will not change the "string" after the byte stream reading to json, to process it using rules
readStream.on("end",()=>{
console.log(typeof data,data.constructor); //1
var tmp = data.replace(/\/\*(\s|.)*?\*\//g,"");
console.log(tmp); //2
})
now the first console.log print string function String () {[native code]}