juniorNode.js
Junior: Understanding the Node.js Buffer Class (Topic 7)
Updated May 4, 2026
Short answer
The Buffer class is used to handle binary data directly in memory, outside of the V8 heap.
Deep explanation
Since JavaScript was originally designed for strings, Node.js introduced Buffers to deal with TCP streams and file system operations. Buffers represent a fixed-size chunk of memory. They are particularly useful when dealing with binary data from images, files, or network packets.
Real-world example
Reading an image file from the disk and sending it over a socket.
Common mistakes
- Trying to resize a Buffer (they are fixed-size
- you must create a new one).
Follow-up questions
- How is Buffer different from TypedArray?