Instances of Buffer are also instances of Uint8Array in node.js 4.x and higher. Thus, the most efficient solution is to access the buffer's own .buffer property directly, as per https://stackoverflow.com/a/31394257/1375574. The Buffer constructor also takes an ArrayBufferView argument if you need to go the other direction.

Note that this will not create a copy, which means that writes to any ArrayBufferView will write through to the original Buffer instance.


In older versions, node.js has both ArrayBuffer as part of v8, but the Buffer class provides a more flexible API. In order to read or write to an ArrayBuffer, you only need to create a view and copy across.

From Buffer to ArrayBuffer:

function toArrayBuffer(buffer) {
  const arrayBuffer = new ArrayBuffer(buffer.length);
  const view = new Uint8Array(arrayBuffer);
  for (let i = 0; i < buffer.length; ++i) {
    view[i] = buffer[i];
  }
  return arrayBuffer;
}

From ArrayBuffer to Buffer:

function toBuffer(arrayBuffer) {
  const buffer = Buffer.alloc(arrayBuffer.byteLength);
  const view = new Uint8Array(arrayBuffer);
  for (let i = 0; i < buffer.length; ++i) {
    buffer[i] = view[i];
  }
  return buffer;
}
Answer from Martin Thomson on Stack Overflow
🌐
GitHub
gist.github.com › miguelmota › 5b06ae5698877322d0ca
Node.js Buffer to ArrayBuffer · GitHub
function toArrayBuffer(buffer) { return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength); } function toBuffer(byteArray) { return Buffer.from(byteArray); }
🌐
Bun
bun.com › binary data › convert an arraybuffer to a buffer
Convert an ArrayBuffer to a Buffer - Bun
July 25, 2026 - Use the static Buffer.from() method to create a Buffer from an ArrayBuffer.
🌐
npm
npmjs.com › package › buffer-to-arraybuffer
buffer-to-arraybuffer - npm
February 21, 2021 - var bufferToArrayBuffer = require('buffer-to-arraybuffer'); var b = new Buffer(12); b.write('abc', 0); var ab = bufferToArrayBuffer(b); String.fromCharCode.apply(null, new Uint8Array(ab)); // 'abc'
      » npm install buffer-to-arraybuffer
    
Published: Feb 21, 2021
Version: 0.0.6
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer
ArrayBuffer - JavaScript - MDN Web Docs
Returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from begin (inclusive) up to end (exclusive). If either begin or end is negative, it refers to an index from the end of the array, as opposed to from the beginning. ... Creates a new ArrayBuffer with the same byte ...
🌐
GitHub
github.com › jhiesey › to-arraybuffer
GitHub - jhiesey/to-arraybuffer: Get an ArrayBuffer from a Buffer as fast as possible
var toArrayBuffer = require('to-arraybuffer') var buffer = new Buffer(100) // Fill the buffer with some data var ab = toArrayBuffer(buffer) // `ab` now contains the same data as `buffer`
Starred by 20 users
Forked by 8 users
Languages: JavaScript 100.0% | JavaScript 100.0%
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer › transfer
ArrayBuffer.prototype.transfer() - JavaScript - MDN Web Docs
July 21, 2025 - The transfer() method performs the same operation as the structured clone algorithm. It copies the bytes of this ArrayBuffer into a new ArrayBuffer object, then detaches this ArrayBuffer object. See transferring ArrayBuffers for more information. transfer() preserves the resizability of this ...
🌐
Bun
bun.sh › guides › binary data › arraybuffer to buffer
Convert an ArrayBuffer to a Buffer | Bun Guides
const arrBuffer = new ArrayBuffer(64); const nodeBuffer = Buffer.from(arrBuffer); To create a Buffer that only views a portion of the underlying buffer, pass the offset and length to Buffer.from().
Find elsewhere
🌐
JavaScript.info
javascript.info › tutorial › binary data, files
ArrayBuffer, binary arrays
July 11, 2022 - Let’s eliminate a possible source of confusion. ArrayBuffer has nothing in common with Array: It has a fixed length, we can’t increase or decrease it. It takes exactly that much space in the memory. To access individual bytes, another “view” object is needed, not buffer[index].
🌐
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.11.1 Documentation
When creating a Buffer using a <TypedArray>'s .buffer, it is possible to use only a portion of the underlying <ArrayBuffer> by passing in byteOffset and length parameters.
🌐
W3Schools
w3schools.com › js › js_arraybuffers.asp
JavaScript Array Buffer
Typed Arrays and DataViews provide a way to read and write numeric values to an ArrayBuffer.
🌐
DEV Community
dev.to › dharamgfx › mastering-javascript-arraybuffer-a-comprehensive-guide-1d5h
🚀 Mastering JavaScript ArrayBuffer: A Comprehensive Guide - DEV Community
June 3, 2024 - ArrayBuffer.prototype.slice(begin, end): Returns a new ArrayBuffer that is a copy of this buffer from begin to end.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Response › arrayBuffer
Response: arrayBuffer() method - Web APIs - MDN Web Docs
November 7, 2025 - The arrayBuffer() method of the Response interface takes a Response stream and reads it to completion. It returns a promise that resolves with an ArrayBuffer.
🌐
GitHub
github.com › miguelmota › arraybuffer-to-buffer
GitHub - miguelmota/arraybuffer-to-buffer: Convert ArrayBuffer to Buffer · GitHub
May 24, 2022 - var arrayBufferToBuffer = require('arraybuffer-to-buffer'); var ab = new ArrayBuffer(12); var v = new DataView(ab); [].slice.call('abc').forEach(function(s, i) { v[i] = s.charCodeAt(0); }); var b = arrayBufferToBuffer(ab); b.toString('utf8', 0, 3); // 'abc'
Starred by 11 users
Forked by 3 users
Languages: JavaScript
🌐
TutorialsPoint
tutorialspoint.com › article › How-to-convert-a-binary-NodeJS-Buffer-to-JavaScript-ArrayBuffer
How to convert a binary NodeJS Buffer to JavaScript ArrayBuffer?
June 24, 2020 - The simplest approach is to access the buf.buffer property directly. However, this creates a view of the underlying ArrayBuffer, not a copy.
🌐
Telerik
telerik.com › blogs › array-buffers-javascript
Array Buffers in JavaScript
October 22, 2025 - In the code above, we are reading the code of different data types stored in the buffer and getting them according to their offset. JavaScript provides several methods to convert between strings and ArrayBuffers, which is essential for tasks such as encoding, decoding and managing data streams.
🌐
npm
npmjs.com › package › arraybuffer-to-buffer
arraybuffer-to-buffer - npm
August 1, 2019 - Latest version: 0.0.7, last published: 7 years ago. Start using arraybuffer-to-buffer in your project by running `npm i arraybuffer-to-buffer`. There are 34 other projects in the npm registry using arraybuffer-to-buffer.
      » npm install arraybuffer-to-buffer
    
Published: Aug 01, 2019
Version: 0.0.7
Author: Miguel Mota