Sunday, 11 June 2017

Read multiple files in Node js and send JSON data

I have multiple files that contains data with time stamps, so I want to read these files in order (and line by line), but I found most of the Node packages use asynchronous method to read files, how can I read each line in order and store all the data in to one string before sending it?

I want to do something like:

    function callbackReadFilesAndSend(res, req){
      var data = ""
      for(int i=0; i<numOfFiles;i++){
     //read lines from files
          data+=...//data from Files[i]
     }
   res.send(data)

}

But I think synchronous methods are bad to use in practice.

Thank you.



via Deidara

No comments:

Post a Comment