const buf1 = Buffer.alloc(4); // create a new buffer with 4 bytes console.log(buf1.byteLength); // prints 4
const buf2 = Buffer.from('hello'); // create a new buffer from a string console.log(buf2.byteLength); // prints 5
const buf3 = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); // create a new buffer from an array of bytes console.log(buf3.byteLength); // prints 6These examples demonstrate how to use the byteLength property to get the length of a buffer in bytes. The package library used for the buffer object is built-in and comes with the Node.js runtime environment.