How to get the length of the Buffer in Node.js?

October 2, 2020 - 1 min read

To get the length of a Buffer instance in Node.js, you can use the length property in the Buffer instance.

Let's say we have a buffer from the string Hello World! like this,

// Buffer from string Hello World!
const buff = Buffer.from("Hello World!", "utf-8");

Now let's get its length using the property length in the buff object.

// Buffer from string Hello World!
const buff = Buffer.from("Hello World!", "utf-8");

// get the length of the Buffer
const length = buff.length;

console.log(length); // 12

See this example live in repl.it.

Feel free to share if you found this useful 😃.