Node.js: Convert an Array to Buffer – A Step Guide

In this tutorial, we will use an example to show how to convert a javascript array to buffer in node.js

Node.js - Convert an Array to Buffer - A Step Guide

1.Create an array

const testArray = [254, 255, 256, 257, 258];

2.Convert array to buffer

const buffer = Buffer.from(testArray);
 
console.log(buffer);

In this tutorial, we use Buffer.from() function to convert an array to buffer.

Run this code, you will see:

node.js - convert an array to buffer