Introduction
Buffers let Node.js handle raw binary data. They help work with files, network data, or images that are not just text.
Jump into concepts and practice - no test required
Buffers let Node.js handle raw binary data. They help work with files, network data, or images that are not just text.
const buffer = Buffer.from('hello');
const buf1 = Buffer.from('hello');
const buf2 = Buffer.alloc(5);const buf3 = Buffer.from([1, 2, 3]);
This code creates a buffer from the string 'Hi!'. It prints the raw bytes and then converts it back to a string.
import { Buffer } from 'node:buffer'; const buf = Buffer.from('Hi!'); console.log(buf); console.log(buf.toString());
Buffers are fixed size and hold raw binary data.
They are essential for working with non-text data in Node.js.
Buffers store raw binary data in Node.js.
They are needed when working with files, networks, or any non-text data.
You can create buffers from strings, arrays, or allocate empty space.
const buf = Buffer.from('abc');
console.log(buf[0]);const buf = Buffer.alloc(5);
buf.write('hello world');
console.log(buf.toString());