Buffer

It is a global class that can be accessed in an application without importing the buffer module. It can be constructed in a variety of ways like var buf = new Buffer(5);

Use of a buffer in Node JS

Buffer is used to dealing with TCP streams, reading, and writing data to the filesystem in the Node.js server, which are purely binary teams of data.

It is designed in a way that is easy to manage, faster and has an API designed for binary data, which makes it the perfect choice for handling streams of data.

Stream

these are the objects that allow the developers to read the data from the source or can write the data to the destination in an endless manner. They usually have problems with the large data. With a stream, there is no need to wait for the whole resource to load.

There are different types of Stream:

  • Readable
  • Writable
  • Duplex
  • Transfer
BY Best Interview Question ON 21 Feb 2021