Buffer

The Buffer class provides an efficient way to handle binary data.

Binary data is often called "raw data", because it's exactly that - arbitrary sequences of bytes. Unlike strings, which are immutable and internally represented in different ways, binary data is fundamentally just a mutable sequence of numbers.

Buffer is a global constructor in Node.js, meaning you don't need to require it.

Loading TypeScript...

Creating a Buffer

The static Buffer.from method is used to create a new Buffer from existing data. It is a safe and common way to work with binary data in Node.js.

Loading TypeScript...

Allocate a Buffer

The Buffer.alloc method creates an empty Buffer of the given size.

Loading TypeScript...

Was this page helpful?