You are building a chat application and need to implement a feature to upload and download files. How would you use streams in Node.js to handle file transfers efficiently between the client and the server?

  • Read the entire file into memory on the server, then send it to the client in one go.
  • Stream the file from the client to the server using a Readable stream, and then save it to disk on the server using a Writable stream.
  • Use HTTP GET and POST requests to send files between the client and server.
  • Compress the file before transferring it to reduce bandwidth usage.
To efficiently handle file transfers in a chat application, you should stream the file from the client to the server using a Readable stream and then save it to disk on the server using a Writable stream. This approach avoids loading the entire file into memory and is suitable for large file transfers.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *