Node.js Buffer API Interview Questions

Prepare for Node.js interviews and strengthen your backend development skills with this comprehensive Buffer API flashcard set. The collection covers the complete Node.js Buffer ecosystem, including Buffer creation, memory allocation, binary data processing, character encodings, TypedArray compatibility, reading and writing numeric values, byte manipulation, and performance considerations. You'll learn how Buffer objects work internally, when to use Buffer.alloc() versus Buffer.allocUnsafe(), how Node.js handles UTF-8 and other encodings, and how to efficiently process network packets, file streams, and binary protocols. The cards also explore Buffer comparison, concatenation, copying, iteration, serialization, and interaction with ArrayBuffer and Uint8Array. Designed for both interview preparation and practical development, this set helps developers understand common Buffer-related questions asked in Node.js, backend, and full-stack engineering interviews. It also serves as a useful reference for working with file systems, networking, cryptography, data parsing, and high-performance applications. Whether you're preparing for a technical interview, reviewing Node.js fundamentals, onboarding new team members, or improving your understanding of binary data processing, these flashcards provide concise explanations and quick knowledge reinforcement. Suitable for Junior, Middle, Senior, and Lead Node.js developers who want to deepen their understanding of one of the most important low-level APIs in the Node.js runtime. You may also be interested in: Master Node.js: From Basics to Production Node.js Stream Module Node.js Cluster Module Node.js Child Process Module Node.js Crypto Module Node.js Operating System Module Node.js File System Module

Knowledge check

Take a test before studying to see which topics you know and where the gaps are.

Take the test

Messenger lessons

Study cards and revisit what you have learned in interactive lessons.

How lessons work

Spaced repetition

Get individual cards to review at intervals that help you remember them longer.

How repetition works
Buffer

Buffer objects are used to represent a fixed-length sequence of bytes.


Many Node.js APIs support Buffers.

1/85
Buffers and character encodings

When converting between Buffers and strings, a character encoding may be specified.


If no character encoding is specified, UTF-8 will be used as the default.

2/85
Buffers and TypedArrays

Buffer instances are also JavaScript Uint8Array and TypedArray instances.


All TypedArray methods are available on Buffers.


There are, however, subtle incompatibilities between the Buffer API and the TypedArray API.

3/85
Buffers and iteration

Buffer instances can be iterated over using for..of syntax.


Additionally, the buf.values(), buf.keys(), and buf.entries() methods can be used to create iterators.

A Buffer is iterable. A for...of loop visits its byte values in order. The related methods provide different views: buf.values() yields values, buf.keys() yields indexes, and buf.entries() yields [index, byte] pairs. Iterating a Buffer does not decode its bytes into characters; call buf.toString() with an encoding to do that.

4/85
Buffer.alloc(size[, fill[, encoding]])

size <integer> The desired length of the new Buffer.


fill <string> | <Buffer> | <Uint8Array> | <integer> A value to pre-fill the new Buffer with. Default: 0.

5/85
Buffer.allocUnsafe(size)

size <integer> The desired length of the new Buffer.


Returns: <Buffer>

6/85
Buffer.allocUnsafeSlow(size)

size <integer> The desired length of the new Buffer.


Returns: <Buffer>

7/85
Buffer.byteLength(string[, encoding])

string <string> | <Buffer> | <TypedArray> | <DataView> | <ArrayBuffer> | <SharedArrayBuffer> A value to calculate the length of.

8/85
Buffer.compare(buf1, buf2)

buf1 <Buffer> | <Uint8Array>


buf2 <Buffer> | <Uint8Array>

9/85
Buffer.concat(list[, totalLength])

list <Buffer[]> | <Uint8Array[]> List of Buffer or Uint8Array instances to concatenate.


totalLength <integer> Total length of the Buffer instances in list when concatenated.

10/85
Buffer.copyBytesFrom(view[, offset[, length]])

view <TypedArray> The <TypedArray> to copy.


offset <integer> The starting offset within view. Default:: 0.

11/85
Buffer.from(array)

array <integer[]>


Returns: <Buffer>

12/85
Buffer.from(arrayBuffer[, byteOffset[, length]])

arrayBuffer <ArrayBuffer> | <SharedArrayBuffer> An ArrayBuffer, SharedArrayBuffer, for example the .buffer property of a TypedArray.

13/85
Buffer.from(buffer)

buffer <Buffer> | <Uint8Array> An existing Buffer or Uint8Array from which to copy data.


Returns: <Buffer>

14/85
Buffer.from(object[, offsetOrEncoding[, length]])

object <Object> An object supporting Symbol.toPrimitive or valueOf().


offsetOrEncoding <integer> | <string> A byte-offset or encoding.

15/85
Buffer.from(string[, encoding])

string <string> A string to encode.


encoding <string> The encoding of string. Default: 'utf8'.


Returns: <Buffer>

16/85
Buffer.isBuffer(obj)

obj <Object>


Returns: <boolean>


Returns true if obj is a Buffer, false otherwise.

Buffer.isBuffer(obj) is a type check. It returns true for a Node.js Buffer and false for other values, including an ordinary Uint8Array. Use it before relying on Buffer-specific methods. A Buffer is also a Uint8Array, but the reverse is not always true.

17/85
Buffer.isEncoding(encoding)

encoding <string> A character encoding name to check.


Returns: <boolean>

18/85
Buffer.poolSize

<integer> Default: 8192


This is the size (in bytes) of pre-allocated internal Buffer instances used for pooling. This value may be modified.

Buffer.poolSize controls the size of the internal memory pool used for some small Buffer allocations. Its default is 8192 bytes. It is a class property, not the length of an individual Buffer. Changing it affects later allocations that use the pool; it does not resize Buffers that have already been created.

19/85
buf[index]

index <integer>


The index operator [index] can be used to get and set the octet at position index in buf. The values refer to individual bytes, so the legal value range is between 0x00 and 0xFF (hex) or 0 and 255 (decimal).

20/85
buf.buffer

<ArrayBuffer> The underlying ArrayBuffer object based on which this Buffer object is created.

21/85
buf.byteOffset

<integer> The byteOffset of the Buffers underlying ArrayBuffer object.

22/85
buf.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])

target <Buffer> | <Uint8Array> A Buffer or Uint8Array with which to compare buf.


targetStart <integer> The offset within target at which to begin comparison. Default: 0.

23/85
buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]])

target <Buffer> | <Uint8Array> A Buffer or Uint8Array to copy into.


targetStart <integer> The offset within target at which to begin writing. Default: 0.

24/85
buf.entries()

Returns: <Iterator>


Creates and returns an iterator of [index, byte] pairs from the contents of buf.

buf.entries() returns an iterator over [index, byte] pairs. For Buffer.from([10, 20]), successive entries are [0, 10] and [1, 20]. It does not create a copied Buffer. Use buf.keys() for indexes alone or buf.values() for byte values alone.

25/85
buf.equals(otherBuffer)

otherBuffer <Buffer> | <Uint8Array> A Buffer or Uint8Array with which to compare buf.


Returns: <boolean>

26/85
buf.fill(value[, offset[, end]][, encoding])

value <string> | <Buffer> | <Uint8Array> | <integer> The value with which to fill buf. Empty value (string, Uint8Array, Buffer) is coerced to 0.


offset <integer> Number of bytes to skip before starting to fill buf. Default: 0.

27/85
buf.includes(value[, byteOffset][, encoding])

value <string> | <Buffer> | <Uint8Array> | <integer> What to search for.


byteOffset <integer> Where to begin searching in buf. If negative, then offset is calculated from the end of buf. Default: 0.

28/85
buf.indexOf(value[, byteOffset][, encoding])

value <string> | <Buffer> | <Uint8Array> | <integer> What to search for.


byteOffset <integer> Where to begin searching in buf. If negative, then offset is calculated from the end of buf. Default: 0.

29/85
buf.keys()

Returns: <Iterator>


Creates and returns an iterator of buf keys (indexes).

buf.keys() returns an iterator of numeric byte indexes from 0 through buf.length - 1. It does not return the byte values. Use buf.values() to iterate values, or buf.entries() to obtain an [index, byte] pair at each position. The iterator can be consumed in a for...of loop.

30/85
buf.lastIndexOf(value[, byteOffset][, encoding])

value <string> | <Buffer> | <Uint8Array> | <integer> What to search for.


byteOffset <integer> Where to begin searching in buf. If negative, then offset is calculated from the end of buf. Default: buf.length - 1.

31/85
buf.length

<integer>


Returns the number of bytes in buf.

buf.length is the number of bytes in a Buffer, not the number of characters in its decoded text. A multibyte UTF-8 character can therefore occupy more than one position. The valid byte indexes run from 0 through buf.length - 1. Buffer.byteLength() can calculate the bytes required to encode a string.

32/85
buf.readBigInt64BE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.


Returns: <bigint>

33/85
buf.readBigInt64LE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.


Returns: <bigint>

34/85
buf.readBigUInt64BE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.


Returns: <bigint>

35/85
buf.readBigUInt64LE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.


Returns: <bigint>

36/85
buf.readDoubleBE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 8. Default: 0.


Returns: <number>


Reads a 64-bit, big-endian double from buf at the specified offset.

37/85
buf.readDoubleLE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 8. Default: 0.


Returns: <number>

38/85
buf.readFloatBE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <number>


Reads a 32-bit, big-endian float from buf at the specified offset.

39/85
buf.readFloatLE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <number>


Reads a 32-bit, little-endian float from buf at the specified offset.


40/85
buf.readInt8([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.


Returns: <integer>


Reads a signed 8-bit integer from buf at the specified offset.

41/85
buf.readInt16BE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.


Returns: <integer>


Reads a signed, big-endian 16-bit integer from buf at the specified offset.

42/85
buf.readInt16LE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.


Returns: <integer>


Reads a signed, little-endian 16-bit integer from buf at the specified offset.

43/85
buf.readInt32BE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer>


Reads a signed, big-endian 32-bit integer from buf at the specified offset.

44/85
buf.readInt32LE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer>


Reads a signed, little-endian 32-bit integer from buf at the specified offset.

45/85
buf.readIntBE(offset, byteLength)

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.


byteLength <integer> Number of bytes to read. Must satisfy 0 < byteLength <= 6.


Returns: <integer>

46/85
buf.readIntLE(offset, byteLength)

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.


byteLength <integer> Number of bytes to read. Must satisfy 0 < byteLength <= 6.


Returns: <integer>

47/85
buf.readUInt8([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.


Returns: <integer>


Reads an unsigned 8-bit integer from buf at the specified offset.

48/85
buf.readUInt16BE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.


Returns: <integer>


Reads an unsigned, big-endian 16-bit integer from buf at the specified offset.

49/85
buf.readUInt16LE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.


Returns: <integer>


Reads an unsigned, little-endian 16-bit integer from buf at the specified offset.

50/85
buf.readUInt32BE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer>


Reads an unsigned, big-endian 32-bit integer from buf at the specified offset.

51/85
buf.readUInt32LE([offset])

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer>


Reads an unsigned, little-endian 32-bit integer from buf at the specified offset.

52/85
buf.readUIntBE(offset, byteLength)

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.


byteLength <integer> Number of bytes to read. Must satisfy 0 < byteLength <= 6.


Returns: <integer>

53/85
buf.readUIntLE(offset, byteLength)

offset <integer> Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - byteLength.


byteLength <integer> Number of bytes to read. Must satisfy 0 < byteLength <= 6.


Returns: <integer>

54/85
buf.subarray([start[, end]])

start <integer> Where the new Buffer will start. Default: 0.


end <integer> Where the new Buffer will end (not inclusive). Default: buf.length.


Returns: <Buffer>

55/85
buf.swap16()

Returns: <Buffer> A reference to buf.


Interprets buf as an array of unsigned 16-bit integers and swaps the byte order in-place.


Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 2.

56/85
buf.swap32()

Returns: <Buffer> A reference to buf.


Interprets buf as an array of unsigned 32-bit integers and swaps the byte order in-place.


Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 4.

57/85
buf.swap64()

Returns: <Buffer> A reference to buf.


Interprets buf as an array of 64-bit numbers and swaps byte order in-place.


Throws ERR_INVALID_BUFFER_SIZE if buf.length is not a multiple of 8.

58/85
buf.toJSON()

Returns: <Object>


Returns a JSON representation of buf. JSON.stringify() implicitly calls this function when stringifying a Buffer instance.

59/85
buf.toString([encoding[, start[, end]]])

encoding <string> The character encoding to use. Default: 'utf8'.


start <integer> The byte offset to start decoding at. Default: 0.


end <integer> The byte offset to stop decoding at (not inclusive). Default: buf.length.

60/85
buf.values()

Returns: <Iterator>


Creates and returns an iterator for buf values (bytes). This function is called automatically when a Buffer is used in a for..of statement.

buf.values() returns an iterator over the Buffer’s byte values in index order. For Buffer.from([10, 20]), it yields 10 and then 20. It does not yield indexes or decoded characters. Use buf.keys() for indexes and buf.entries() for [index, byte] pairs. A for...of loop over a Buffer also iterates byte values.

61/85
buf.write(string[, offset[, length]][, encoding])

string <string> String to write to buf.


offset <integer> Number of bytes to skip before starting to write string. Default: 0.


length <integer> Maximum number of bytes to write (written bytes will not exceed buf.length - offset). Default: buf.length - offset.

62/85
buf.writeBigInt64BE(value[, offset])

value <bigint> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.


Returns: <integer> offset plus the number of bytes written.

63/85
buf.writeBigInt64LE(value[, offset])

value <bigint> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.


Returns: <integer> offset plus the number of bytes written.

64/85
buf.writeBigUInt64BE(value[, offset])

value <bigint> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.


Returns: <integer> offset plus the number of bytes written.

65/85
buf.writeBigUInt64LE(value[, offset])

value <bigint> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8. Default: 0.


Returns: <integer> offset plus the number of bytes written.

66/85
buf.writeDoubleBE(value[, offset])

value <number> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 8. Default: 0.


Returns: <integer> offset plus the number of bytes written.

67/85
buf.writeDoubleLE(value[, offset])

value <number> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 8. Default: 0.


Returns: <integer> offset plus the number of bytes written.

68/85
buf.writeFloatBE(value[, offset])

value <number> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer> offset plus the number of bytes written.

69/85
buf.writeFloatLE(value[, offset])

value <number> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer> offset plus the number of bytes written.

70/85
buf.writeInt8(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.


Returns: <integer> offset plus the number of bytes written.

71/85
buf.writeInt16BE(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.


Returns: <integer> offset plus the number of bytes written.

72/85
buf.writeInt16LE(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.


Returns: <integer> offset plus the number of bytes written.

73/85
buf.writeInt32BE(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer> offset plus the number of bytes written.

74/85
buf.writeInt32LE(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer> offset plus the number of bytes written.

75/85
buf.writeIntBE(value, offset, byteLength)

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength.


byteLength <integer> Number of bytes to write. Must satisfy 0 < byteLength <= 6.

76/85
buf.writeIntLE(value, offset, byteLength)

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength.


byteLength <integer> Number of bytes to write. Must satisfy 0 < byteLength <= 6.

77/85
buf.writeUInt8(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 1. Default: 0.


Returns: <integer> offset plus the number of bytes written.

78/85
buf.writeUInt16BE(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.


Returns: <integer> offset plus the number of bytes written.

79/85
buf.writeUInt16LE(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2. Default: 0.


Returns: <integer> offset plus the number of bytes written.

80/85
buf.writeUInt32BE(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer> offset plus the number of bytes written.

81/85
buf.writeUInt32LE(value[, offset])

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4. Default: 0.


Returns: <integer> offset plus the number of bytes written.

82/85
buf.writeUIntBE(value, offset, byteLength)

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength.


byteLength <integer> Number of bytes to write. Must satisfy 0 < byteLength <= 6.

83/85
buf.writeUIntLE(value, offset, byteLength)

value <integer> Number to be written to buf.


offset <integer> Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength.


byteLength <integer> Number of bytes to write. Must satisfy 0 < byteLength <= 6.

84/85
Buffer constants

buffer.constants.MAX_LENGTH


<integer> The largest size allowed for a single Buffer instance.

85/85