Node.js Buffer Create

Introduction

Method 1:Following is the syntax to create an uninitiated Buffer of 10 octets:

var buf = Buffer.alloc(10);
console.log(buf);

Method 2:Following is the syntax to create a Buffer from a given array:

var buf = Buffer.from([10, 20, 30, 40, 50]);
console.log(buf);

Method 3:Following is the syntax to create a Buffer from a given string and optionally encoding type:

var buf = Buffer.from("Simply Easy Learning", "utf-8");
console.log(buf);



PreviousNext

Related