DEV Community

Cover image for How to get the length of the Buffer in Node.js?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

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

Originally posted here!

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");
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

See this example live in repl.it.

Feel free to share if you found this useful 😃.


AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

If you found this post useful, consider leaving a ❤️ or a nice comment!

Got it