Buffers in nodejs

Buffers are used to handle binary data in Node.js. They represent a fixed-size chunk of memory outside the V8 heap. They are essential for dealing with streams of binary data from the network, filesystem, or other I/O sources.

Example

const buf = Buffer.from('hello', 'utf8');
console.log(buf.toString('hex'));
console.log(buf[0]); // 104 (ASCII for 'h')

Creating a buffer from a string and accessing its hexadecimal representation and byte values.