Buffer Module in Node.js

From the Node.js Core Modules cheat sheet · Crypto & Buffer · verified Jul 2026

Buffer Module

Handle binary data and convert between encodings

javascript
// Create buffers
const buf1 = Buffer.alloc(10);
const buf2 = Buffer.from('Hello');
const buf3 = Buffer.from([1, 2, 3]);

// Read/Write
buf1.write('Hello');
console.log(buf1.toString());

// Compare
Buffer.compare(buf1, buf2);
💡 Buffers are fixed-size byte arrays
📌 Use Buffer.from() not new Buffer() (deprecated)
⚡ Buffers are more memory efficient than strings
⚠️ Be careful with buffer overflows
🔗 Related: stream.Buffer for streaming operations

Continue with Node.js Core Modules

Save the full cheat sheet or work through every related task.

More Node.js tasks

Back to the full Node.js Core Modules cheat sheet