Learn all there is to know about Buffers in NodeJS

Have you been a Node developer for years, but have never come across Node Buffers? Maybe, you have come across the term a few times, but always shied away from learning what buffers are? You may have never actually needed to use buffers before. Node.js is not a language that forces programmers to deal directly with how programs manage memory. But if you are committed to going the extra mile to become an expert Node developer, you’ll have to grapple with concepts like buffers to understand how Node works under the hood.

At first glance, you’ll feel like Node Buffers are such a complicated topic to understand. But in reality, that’s not the case. The problem starts when all the online tutorials you look at start with creating Node Buffers and manipulating them without first explaining what actually buffers are. To not make the same mistake here, I’ll have to explain what buffers are first. But before understanding what buffers are, we have to tackle a few other concepts that come up when trying to understand buffers.

To understand buffers properly, we should understand about binary data, character encoding, and streams. If you don’t see how these things matter to buffers yet, don’t worry, they all come together, in the end, to explain what buffers are.

What is Binary Data?

If you already know what binary data are, you can skip to the next topic directly. Others should just hold on to see what binary data are.

The binary number system is another number system like the decimal number system we use. Unlike the decimal number system, which uses digits from 0-9 to represent numbers, the binary number system uses only the digits 0 and 1 to represent numbers. Here are some examples of binary numbers.

0, 1, 10, 101, 1011011, 1000101

Each digit in a binary number is considered as a Bit in Computer Science. A combination of 8 bits is called a Byte. But what does Computer Science has to do with binary numbers? Computers use binary numbers to store and represent data. So, every type of data stored in computers is ultimately stored as a set of binary numbers. We call these data Binary Data.

To store every type of data as binary data, computers should know how to convert them to binary data. Computers have different mechanisms to achieve this. Let’s see what they are.

#node

A Complete Introduction to Node Buffers
1.65 GEEK