What is the length property in Buffer module of Node.js?

The length property in the Buffer module of Node.js denotes the number of data-elements stored inside a buffer.

The length of the following buffer is 5, as it contains 5 values:

%0 node_1625727698073 0 node_1 1 node_2 2 node_3 3 node_1625727684280 4
Buffer of 5 integers

Syntax

To access the length property of a buffer, the following syntax is used:

buffer.length

The identifier buffer is the name of a pre-allocated buffer.

Return value

It returns the size or length of the buffer.

Example

The following program allocates a buffer filled with a custom string using the Buffer.from function. The identifier for it is buffer. The console.log function is used to print the value of the length property of buffer on the console:

var buffer = Buffer.from('Educative');
console.log(buffer.length);

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved