What is Buffer in Node.js?

A buffer is an area of memory. JavaScript developers are not familiar with this concept as C, C++ developers have. It represents a fixed-size chunk of memory allocated outside of the V8 JavaScript engine. It helps developers to deal with binary data. Buffer in node.js is not related to the concept of buffering data.

Buffer can be created using :


const buf= Buffer.form(“Hello”)


const buf= Buffer.alloc(1024)


const buf= Buffer.allocUnsafe(1024)

You can write to a buffer a whole string of data by using the write() method:


The buf.toString() method is used to read the data from a node buffer:

buf.toString(encoding, start, end)