Skip to content

Latest commit

 

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Streamer

In the Node.js, there are several ways to stream a file from back-end to front-end:

  • Creating a HTTP server in Node.js and using the fs module to read the file and write it to the HTTP response.
  • Streams API
  • Using a third-party libraries such as FileStream, Multer, or Formidable

Creating a HTTP server is more straightforward and better to understand. However, The Streams API provides more flexibility. The front-end will be created later to show the file sent to it by streaming. The front-end needs to communicate with the back-end again and send the changed parts to the back-end. Streams API can act with more flexibility in this case and it supports different types of streams. And finally, third parties are not considered in this project.

To test the stream manually, use following command in terminal (in windows, use a bash):

curl -o output.txt http://localhost:3000

SOLID

SOLID principle has been considered during the design of this project (backend):

  • Single responsibility Each file does a specific work. Router is for routing only for example.

  • Open Close To add new features, do not modify new ones, instead add new files.

  • Liksov and Interface are more about pure object oriented features.

  • Dependency Inject is for heavy service based solutions using interfaces

TODO

  1. Add unit tests
  2. Consider file upload and download when the file is too big. They need to be streamed.
  3. Sanitize file name of uploaded file to prevent access to parent directory for example (upload API)
  4. Be aware of file content. for example do not allow uploading js or python codes
  5. Guard against common XSS and other script attacks

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages