You can use Buffer.from(string[, encoding]). The Buffer class has implemented the Uint8Array interface in Node since v4.x. You can also optionally specify an encoding with which to do string processing in both directions, i.e. buffer.toString([encoding]).
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array
Uint8Array - JavaScript - MDN Web Docs
Uint8Array is a subclass of the hidden TypedArray class.
Top answer 1 of 3
36
You can use Buffer.from(string[, encoding]). The Buffer class has implemented the Uint8Array interface in Node since v4.x. You can also optionally specify an encoding with which to do string processing in both directions, i.e. buffer.toString([encoding]).
2 of 3
30
Why not simply using:
const resEncodedMessage = new TextEncoder().encode(message)
Start moving to Uint8Array in new APIs?
There was a suggestion by @jasnell to use Uint8Arrays in new APIs over Buffers as well as a weigh-in by @sindresorhus saying it is easier to author cross-platform APIs when using Uint8Arrays. Here ... More on github.com
Buffer/Uint8Array using lots of memory
Tested in NodeJS Versions: v22.3.0, v20.14.0, v18.20.3, v16.20.2 It appears as though Buffer/Uint8Array consumes much more memory than I would expect. This is particularly obvious with many small i... More on github.com
» npm install uint8arrays
Published: May 07, 2026
Version: 6.1.1
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.11.1 Documentation
Node.js APIs accept plain <Uint8Array>s wherever Buffers are supported as well.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8Array › Uint8Array
Uint8Array() constructor - JavaScript - MDN Web Docs
July 10, 2025 - The Uint8Array() constructor creates Uint8Array objects. The contents are initialized to 0 unless initialization data is explicitly provided.
Stack Overflow
stackoverflow.com › questions › 70734367 › nodejs-uint8array-uint16array-uint32array
javascript - Nodejs Uint8Array,Uint16Array, Uint32Array
To access its underlying buffer (and construct the typed array as a view on it), you need to write new Uint16Array(buffer.buffer); and new Uint8Array(buffer.buffer);.
npm
npmjs.com › package › to-uint8array
to-uint8array - npm
July 16, 2021 - import toUint8 from 'to-uint8array' const buffer = Buffer.from('abc') const u8 = new Uint8Array([97]) const u16 = new Uint16Array([0, 1, 2]) const ab = new ArrayBuffer(3) toUint8(u16) // Uint8Array(6) [ 0, 0, 1, 0, 2, 0 ] toUint8(ab) // Uint8Array(3) [ 0, 0, 0 ] toUint8('abc') // Uint8Array(3) [ 97, 98, 99 ] toUint8(buffer) // Uint8Array(3) [ 97, 98, 99 ] toUint8(u8) === u8 // true toUint8(u16) === u16 // false toUint8(ab).buffer === ab // true toUint8(u16).buffer === u16.buffer // true toUint8(buffer) instanceof Uint8Array // true toUint8(buffer) instanceof Buffer // false
» npm install to-uint8array
Published: Jul 16, 2021
Version: 0.1.1
Author: Jimmy Wärting
Repository: https://github.com/jimmywarting/to-uint8array
Sindre Sorhus
sindresorhus.com › blog › goodbye-nodejs-buffer
Goodbye, Node.js Buffer — Sindre Sorhus
October 24, 2023 - Instead of Buffer#slice(), use Uint8Array#subarray() or Buffer#subarray().
Medium
mookypoo.medium.com › receiving-uint8array-on-node-js-and-saving-on-google-cloud-storage-5682a3151edc
Receiving Uint8Array on Node.js and Saving on Google Cloud Storage | by Soo Kim | Medium
June 3, 2022 - In my previous post, I used bucket.upload() but after some googling, I’ve switched to file.save(), which takes a Buffer as an argument. (1) When you receive the bytes array, create an instance of Uint8Array, which is extended by the Buffer class. (2) Use bucket.file(filename) to create a File object.
npm
npmjs.com › package › buffer-to-uint8array
buffer-to-uint8array - npm
Convert buf, a Buffer or string to a Uint8Array.
» npm install buffer-to-uint8array
Published: May 20, 2015
Version: 1.1.0
Author: substack
Repository: https://github.com/substack/buffer-to-uint8array
npm
npmjs.com › search
uint8array - npm search
Fast SHA-1 digest hash based on Uint8Array, pure JavaScript.
Bun
bun.com › binary data › convert a buffer to a uint8array
Convert a Buffer to a Uint8Array - Bun
July 7, 2026 - The Node.js Buffer class extends Uint8Array, so no conversion is needed.