node.js fs.read() example

后端 未结 4 1748
逝去的感伤
逝去的感伤 2020-12-17 15:41
app=function(req,res)
{
 res.writeHead(200,{\'Content-Type\':\'text/plain\'})
 var buffer=new Buffer(100)
 var fs=require(\'fs\')
 fs.open(\'.\'+req.url,\'r\',functi         


        
4条回答
  •  春和景丽
    2020-12-17 15:51

    Since you've designed your app to process files one after another (synchronously), you need to use fs.readSync() but be warned that, while your app is reading a file in this way, it cannot do anything else.

    A better approach would be to process the files in the "node way", that is asynchronously.

    -- node.fs - one line, no waiting

提交回复
热议问题