The Wayback Machine - https://web.archive.org/web/20240930183950/https://www.geeksforgeeks.org/node-js-buffer-complete-reference/
Open In App

Node.js Buffer Complete Reference

Last Updated : 05 Dec, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Buffers are instances of the Buffer class in Node.js. Buffers are designed to handle binary raw data. Buffers allocate raw memory outside the V8 heap. Buffer class is a global class so it can be used without importing the Buffer module in an application.

Example:

Javascript




<script>
    // Node.js program to demonstrate the
    // Buffer.allocUnsafeSlow() Method
          
    // Creating a buffer
    const buffer = Buffer.allocUnsafe(10);
          
    // Display the buffer containing random values
    console.log("allocUnsafeSlow() Method");
    console.log(buffer);
</script>


Output:

allocUnsafeSlow() Method
<Buffer 01 00 00 00 00 00 00 00 8b ed>

The Complete List of Node.js Buffer module methods are listed below:

Node.js Buffer

Description

Node.js Buffer.copy() Method Buffer is a temporary memory storage which stores the data when it is being moved from one place to another.
Node.js Buffer.includes() Method The Buffer.includes() method checks whether the provided value is present or included in the buffer or not.
Nodejs Buffer.compare() Method Buffer.compare() method compares the two given buffers.
Node.js Buffer.alloc() Method The Buffer.alloc() method is used to create a new buffer object of the specified size. 
Node.js Buffer.equals() Method The Buffer.equals() method is used to compare two buffer objects and returns
Node.js Buffer.subarray() Method The buffer.subarray() method is an inbuilt application programming interface of the buffer module which is used to crop a part of array
Node.js Buffer.readIntBE() Method The Buffer.readIntBE() method is used to read the number of bytes for a buffer at a given offset and interprets the result as a two’s complement signed value.
Node.js Buffer.write() Method The Buffer.write() method writes the specified string into a buffer, at the specified position.
Node.js Buffer.readIntLE() Method The Buffer.readIntLE() method is used to read a number of bytes from a buffer at a given offset and interprets the result as a two’s complement signed value.
Node.js Buffer.readUInt8() Method The Buffer.readUInt8() method is used to read an unsigned 8-bit integer from a Buffer object.
Node.js Buffer.indexOf() Method Buffer is a temporary memory storage that stores the data when it is being moved from one place to another.
Node.js Buffer.allocUnsafeSlow() Method Buffer is a temporary memory storage that stores the data when it is being moved from one place to another. It’s like the array of integers
Node.js Buffer.writeUInt32BE() Method The Buffer.writeUInt32BE() method is used to write a number to an instance of the Buffer class.
Node.js Buffer.readInt32LE() Method This is used to read a 32-bit integer from a buffer object at a given offset and returns the result in Little endian.
Node.js Buffer.readFloatLE() Method This is used to read a 32-bit float number from the Buffer class with a specified endian format.
Node.js Buffer.writeIntLE() Method Buffer is a temporary memory storage that stores the data when it is being moved from one place to another.
Node.js Buffer.isEncoding() Method The Buffer.isEncoding() method checks whether the given encoding is supported or not.
Node.js Buffer.swap32() Method This is an inbuilt application programming interface of class Buffer within the Buffer module which is used to swap the buffer byte order in-place.
Node.js Buffer.readUInt16BE() Method This is an inbuilt application programming interface of class Buffer within the Buffer module which is used to read a 16-bit value from an allocated buffer at a specified offset.
Node.js Buffer.writeUInt16LE() Method This is used to write specified bytes in Little Endian format to the buffer object. Here, the value should be a valid unsigned 16-bit integer.
Node.js Buffer.readUInt16LE() Method This is used to read an unsigned 16-bit integer from the buffer at the specified offset with a specified little-endian format.
Node.js Buffer.writeFloatBE() Method This is used to write big endian 32 bits floating point value to an allocated buffer at the specified offset
Node.js Buffer.writeUIntLE() Method This is used to write the specified bytes, using little endian, to a Buffer object. It supports up to 48 bits of accuracy.
Node.js Buffer.writeUInt16BE() Method The Buffer.writeUInt16BE() method is used to write specified bytes using Big endian format to the buffer object
Node.js Buffer.readUInt32BE() Method This is used to read a 32-bit value from an allocated buffer at a specified offset.
Node.js Buffer.writeFloatLE() Method The value to the buffer at the specified offset with the specified little-endian format. 
Node.js Buffer.readInt16LE() Method This is used to read 16-bit values from an allocated buffer at a specified offset in Little Endian format.
Node.js Buffer.toString() Method The Buffer.toString() method is used to decode buffer data to string according to the specified encoding type. 
Node.js Buffer.writeUInt8() Method This is used to write values to buffer at the specified offset.
Node.js Buffer.values() Method The Buffer.values() Method is used to create a loop or iterating object which contains the value of each byte of buffer instance.
Node.js Buffer.from() Method The Buffer.from() method is used to create a new buffer containing the specified string, array or buffer.
Node.js Buffer.writeUIntBE() Method Buffer.writeUIntBE() method is used to write the specified bytes using big endian format to a Buffer object.
Node.js Buffer.readInt8() Method The Buffer.readUInt8() method is used to read an unsigned 8-bit integer from a Buffer from a with the specific offset.
Node.js Buffer.concat() Method The Buffer.concat() method is used to concat all buffer objects in a given array into one buffer object.
Node.js Buffer.fill() Method The Buffer.fill() Method puts the data into the buffer instance.
Node.js Buffer.readUIntBE() Method This is used to read specified number of byte(s) value from an allocated buffer at a specified offset.
Node.js Buffer.swap16() Method This is used to swap the buffer byte order in-place. The swapping is performed by interpreting buffer as an array of 16-bit numbers.
Node.js Buffer.writeDoubleBE() Method This is used to writes big endian 64-bits double value to an allocated buffer at the specified offset.
Node.js Buffer.writeUInt32LE() Method This  is used to write specified bytes using Little endian format to the buffer object.
Node.js Buffer.isBuffer() Method The Buffer.isBuffer() method checks whether the provided object is a buffer or not.
Node.js Buffer.keys() Method The Buffer.keys() method is used to return an iterator object, containing the key of every byte in a buffer object.
Node.js Buffer.writeInt32LE() Method The Buffer.writeInt32LE() method is used to write specified bytes into the buffer using little-endian format
Node.js Buffer.readUInt32LE() Method This  is used to read 32-bit value from an allocated buffer at a specified offset in little endian format.
Node.js Buffer.writeIntBE() Method It supports upto 48 bits of accuracy. If the value is other then signed integer then its behavior is undefined.
Node.js Buffer.swap64() Method The Buffer.swap64() method is an inbuilt application programming interface of class Buffer
Node.js Buffer.writeInt16BE() Method This is used to write integer value to buffer at the specified offset with the big-endian format.
Node.js Buffer.readInt16BE() Method Buffer module which reads a 16-bit signed integer from the buffer at the specified offset in the big endian format.
Node.js Buffer.entries() Method The Buffer.entries() method is used to create and return the iterator of [index, byte] pairs from the contents of the buffer.
Node.js Buffer.readDoubleBE() Method The Buffer.readDoubleBE() Method in Node.js is used to read a 64-bit double from the buffer at the given offset with the Big Endian format.
Node.js Buffer.writeDoubleLE() Method Buffer module that writes a value to the buffer at the specified offset with the specified endian format.
Node.js Buffer.writeInt16LE() Method This is used to write a valid signed 16-bit integer to buffer at the specified offset with specified little endian format.
Node.js Buffer.poolSize Property The Buffer.poolSize property is an inbuilt application programming interface of class Buffer
Node.js Buffer.readDoubleLE() Method This  is used to read a 64-bit double from the buffer at the given offset with Little Endian format.
Node.js Buffer.byteLength() Method This is used to return the length in bytes of the specified buffer object.
Node.js Buffer.readFloatBE() Method This  is used to read big endian 32 bits floating-point value to an allocated buffer at the specified offset.
Node.js Buffer.writeInt32BE() Method  This is used to write integer value to buffer at the specified offset with the big-endian format, integer value should be a valid signed 32-bit integer. 
Node.js Buffer.writeInt8() Method This  is used to writes value to an allocated buffer at the specified offset.
Node.js Buffer.readUIntLE() Method This is used to read specified number of byte(s) value from an allocated buffer at a specified offset.
Node.js Buffer.toJSON() Method The Buffer.toJSON() method returns the buffer in JSON format.
Node.js Buffer.lastIndexOf() Method The Buffer.lastIndexOf() Method checks for a given value in the buffer and return its index where it is present.
Node.js Buffer.byteOffset Property The Buffer.byteOffset property is an inbuilt application programming interface of class Buffer
Node.js Buffer.kMaxLength Property The Buffer.kMaxLength property is an inbuilt application programming interface of class Buffer
Node.js Buffer.buffer Property This is used to get the object of array buffer equivalent to this buffer object.
Node.js Buffer.length Property This  is used to get the length of this buffer object.
Node.js Buffer.writeBigInt64BE() Method This  is used to writes big endian 64-bits Big integer value to an allocated buffer at the specified offset.
Node.js Buffer.readBigInt64BE() Method This is used to read 64-bit Big integer from a buffer object at a given offset and returns the result in Big endian.
Node.js Buffer.readBigUInt64LE() Method This  is used to read unsigned 64 bit integer from a buffer object at a given offset and returns the result in Little endian.
Node.js Buffer.writeBigUInt64LE() Method  This is used to writes little endian 64-bits Big integer value to an allocated buffer at the specified offset.
Node.js Buffer.writeBigInt64LE() Method  This is used to writes little endian 64-bits Big integer value to an allocated buffer at the specified offset.
Node.js Buffer.readBigInt64LE() Method This  is used to read 64 bit Big integer from a buffer object at a given offset and returns the result in Little endian.
Node.js Buffer.writeBigUInt64BE() Method This is used to writes big endian 64-bits Big integer value to an allocated buffer at the specified offset.
Node.js Buffer.readBigUInt64BE() Method This is used to read unsigned 64 bit integer from a buffer object at a given offset and returns the result in Big endian .


Previous Article
Next Article

Similar Reads

Node.js Buffer.buffer Property
The Buffer.buffer property is an inbuilt application programming interface of class Buffer within buffer module which is used to get the object of array buffer equivalent to this buffer object. Syntax: const buf.buffer Return Value: This property returns the object of array buffer. Example 1: Filename: index.js C/C++ Code // Node.js program to demo
1 min read
Node.js String Decoder Complete Reference
The string Decoder module provides an API for decoding Buffer objects into strings. Example: C/C++ Code // Node.js program to demonstrate the // stringDecoder.write() Method // Import the string_decoder module // and get the StringDecoder class // using object destructuring const { StringDecoder } = require("string_decoder"); // Create a
1 min read
Node.js HTTP Module Complete Reference
To make HTTP requests in Node.js, there is a built-in module HTTP in Node.js to transfer data over the HTTP. To use the HTTP server in the node, we need to require the HTTP module. The HTTP module creates an HTTP server that listens to server ports and gives a response back to the client. Example: C/C++ Code // Node.js program to demonstrate the //
4 min read
Node.js Crypto Complete Reference
Node.js crypto module handles cryptographic functionality. Cryptography is an important aspect when we deal with network security. ‘Crypto’ means secret or hidden. Cryptography is the science of secret writing with the intention of keeping the data secret. Example: C/C++ Code <script> // Node.js program to demonstrate the // cipher.final() me
5 min read
Node.js Assert Complete Reference
Assert module in Node.js provides a bunch of facilities that are useful for the assertion of the function. The assert module provides a set of assertion functions for verifying invariants. If the condition is true it will output nothing else an assertion error is given by the console. Example: C/C++ Code // Requiring the module const assert = requi
2 min read
Node.js OS Complete Reference
Node.js OS module provides information about the computer operating system. Below example illustrate the os.version() method in Node.js: Example: C/C++ Code // Import the os module const os = require("os"); let osVersion = os.version(); console.log("OS Version:", osVersion); Output: OS Version: Windows 10 Enterprise The Complete
2 min read
Node.js Globals Complete Reference
Node.js Global Objects are the objects that are available in all modules. Global Objects are built-in objects that are part of the JavaScript and can be used directly in the application without importing any particular module. Example: It repeats the execution of the callback after every t time in milliseconds passed as a parameter. C/C++ Code // E
2 min read
Node.js Path Module Complete Reference
The Path Module in Node.js provides the utilities for working with file and directory paths. Example: C/C++ Code // Import the path module const path = require('path'); // CASE 1 // If "dir", "root" and "base" are all given, // "root" is ignored. let path1 = path.format({ root: "C:\\ignored\\root",
2 min read
Node.js Stream Complete Reference
Node.js streams are a type of data-handling method and are used to read or write input into output sequentially. Streams are used to handle reading/writing files or exchanging information efficiently. Example: C/C++ Code // Node.js program to demonstrate the // writable.write() method // Including stream module const stream = require('stream'); //
3 min read
Node.js Query String Complete Reference
Node.js query String module is used as utilities for parsing and formatting URL query strings. It can be used to convert query string into JSON object and vice-versa. Example: C/C++ Code // Import the querystring module const querystring = require("querystring"); // Specify the URL query string // to be parsed let urlQuery = "usernam
1 min read
Node.js HTTP2 Complete Reference
HTTP2 module is used to provide an implementation of the HTTP2 protocol. It reduces overheads by compressing the server request headers. Example: C/C++ Code // Node.js program to demonstrate the // close event method const http2 = require('http2'); const fs = require('fs'); // Private key and public certificate for access const options = { key: fs.
6 min read
Node.js UDP/DataGram Complete Reference
Node.js UDP/DataGram module provides an implementation of UDP datagram sockets. Example: C/C++ Code // Importing dgram module const dgram = require('dgram'); // Creating and initializing client // and server socket const client = dgram.createSocket("udp4"); const server = dgram.createSocket("udp4"); // Catching the message event
2 min read
Node.js URL Complete Reference
The ‘url’ module provides utilities for URL resolution and parsing. The getters and setters implement the properties of URL objects on the class prototype, and the URL class is available on the global object. Example: C/C++ Code // Create a test URLSearchParams object const searchpar = new URLSearchParams("keya=vala&keyb=valb"); // Di
4 min read
Node.js Utility Complete Reference
The Util module in node.js provides access to various utility functions. There are various utility modules available in the node.js module library. The modules are extremely useful in developing node based web applications. The Complete list of utility are listed below: Util Description Utility ModuleIt provides access to various utility functions.
4 min read
Node.js V8 Complete Reference
The v8 module exposes APIs that are specific to the version of V8 built into the Node.js binary. Example: C/C++ Code // Accessing v8 module const v8 = require('v8'); // Calling v8.getHeapStatistics() console.log(v8.getHeapStatistics()); Output: { total_heap_size: 6537216, total_heap_size_executable: 1048576, total_physical_size: 6537216, total_avai
2 min read
Node.js Timers Complete Reference
Node.js Timers module in Node.js contains various functions that allow us to execute a block of code or a function after a set period of time. The Timers module is global, we do not need to use require() to import it. Example: C/C++ Code // Node.js program to demonstrate the // Immediate Class methods // Setting Immediate by setImmediate Method con
2 min read
Node.js TLS/SSL Complete Reference
The tls module provides an implementation of the Transport Layer Security (TLS) and Secure Socket Layer (SSL) protocols that are built on top of OpenSSL. Example: C/C++ Code // Node.js program to demonstrate the // tls.getCiphers() method const tls = require('tls'), fs = require('fs'), // Port and host address for server PORT = 1337, HOST = '127.0.
3 min read
Node.js VM Complete Reference
The VM module enables compiling and running code within V8 Virtual Machine contexts. Example: C/C++ Code // Node.js program to demonstrate the // script.runInContext() method // Including util and vm module const util = require('util'); const vm = require('vm'); // Constructing context const contextobj = { name: 'Nidhi', articles: 60 }; // Construc
2 min read
Node.js Zlib Complete Reference
The zlib module provides compression functionality implemented using Gzip, Deflate/Inflate, and Brotli. The Complete Reference of Zlib are listed below: Methods Description zlib.constantsIt is used to yields an object listing Zlib-related constants. zlib.createBrotliCompress()It is used to create BrotliCompress object. zlib.createBrotliDecompress()
2 min read
Node.js Process Complete Reference
A process object is a global object that gives information about and controls the node.js process. As it is global, it can be used in the project without importing it from any module. Table of Content Understanding Node.js ProcessesEvents and Event-driven ArchitectureExecution Models and Asynchronous ProgrammingUnderstanding Node.js ProcessesSingle
5 min read
Node.js File System Complete Reference
Node.js File System module is used to handle file operations like creating, reading, deleting, etc. Node.js provides an inbuilt module called FS (File System). Node.js gives the functionality of file I/O by providing wrappers around the standard POSIX functions. All file system operations can have synchronous and asynchronous forms depending on use
15+ min read
Node.js Questions Complete Reference
Most people are confused and understand it’s a framework or a programming language. We often use Node.js for building back-end services like APIs like Web App or Mobile App. It’s used in production by large companies such as Paypal, Uber, Netflix, Walmart, and so on. You need to remember that NodeJS is not a framework, and it’s not a programming la
13 min read
Node.js Console Complete Reference
The console module in Node.js provides a set of functions to output information to the terminal or command line, helping with debugging and logging. It is a built-in utility that is essential for monitoring and troubleshooting Node.js applications. It is a global object that provides a simple debugging console similar to JavaScript to display diffe
4 min read
Node.js DNS Complete Reference
Node.js DNS is a node module used to do name resolution facility which is provided by the operating system as well as used to do an actual DNS lookup. Example: [GFGTABS] JavaScript <script> // Node.js program to demonstrate the // dns.resolve() method // Accessing dns module const dns = require('dns'); // Set the rrtype for dns.resolv
3 min read
Node.js Buffer.readUInt16LE() Method
The Buffer.readUInt16LE() method is an inbuilt application programming interface of class Buffer within Buffer module which is used to read an unsigned 16-bit integer from buffer at the specified offset with specified little endian format. Syntax: Buffer.readUInt16LE( offset ) Parameters: This method accepts single parameter offset which denotes th
2 min read
Node.js Buffer.readUInt32BE() Method
The Buffer.readUInt32BE() method is an inbuilt application programming interface of class Buffer within the Buffer module which is used to read 32-bit value from an allocated buffer at a specified offset. Syntax: Buffer.readUInt32BE( offset ) Parameters: This method accept single parameter offset which specifies the number of bytes to skip before r
2 min read
Node.js Buffer.allocUnsafe() Method
The Buffer.allocUnsafe() method is an inbuilt application programming interface of class Buffer with in Buffer module which is used to allocate the buffer of given size but not initialize it. Syntax: const Buffer.allocUnsafe( size) Parameters: This method accepts a single parameter size which holds the desired size of the buffer. Return value: It a
1 min read
Node.js Buffer.writeInt32BE() Method
The Buffer.writeInt32BE() method is an inbuilt application programming interface of class Buffer within Buffer module which is used to write integer value to buffer at the specified offset with the big-endian format, integer value should be a valid signed 32-bit integer. Error is thrown if the value is outside the range of signed 32-bit integer.Int
2 min read
Node.js Buffer.slice() Method
Buffer is a temporary memory storage that stores the data when it is being moved from one place to another, it's like an array of integers. The Buffer.slice() method returns a new Buffer that points to the same memory location as that of the input Buffer with only the cropped elements. Syntax: buffer.slice( start, end ) Parameters: This method acce
2 min read
Node.js Buffer.indexOf() Method
Buffer is a temporary memory storage which stores the data when it is being moved from one place to another. It is like the array of integers. The Buffer.indexOf() method firstly checks for the input value, if it present in the buffer then it returns the first position (index) from where the value is starting. Syntax: buffer.indexOf( value, start,
2 min read