Friday 21 April 2017

Implementing download file function in Node.js

I am trying to implement a function to download a file in Node.js. The way I have implemented it right now is - user enter some parameters and clicks the search button. I fetch data matching those parameters from a database, show that data on a webpage (using graphs) and along with that write that data to a file on the server. Then I am showing a download this data link on the same webpage to download this file. Once a user clicks this link, the file will be downloaded to user's local machine. I am using res.download() method of Express.js to achieve this. This is working perfectly.

Now, I am not sure how to handle the case where more than one user is searching data using different parameters. I have following questions -

1) As I am writing data to same file everytime request comes in, new data may override data from the previous request (from a different user)(how to handle this?).

2) Do I need to create different files depending upon different users (using user id)?

3) Is this the correct way of implementing this or I'm wrong somewhere?

4) What is the best way to implement such a function?

I would really appreciate any suggestions and help. Thank you!



via harsh

No comments:

Post a Comment