To check whether some data or an object is a Buffer
, you can use the isBuffer()
method in the global Buffer
class in Node.js.
// a buffer
const buff = Buffer.alloc(10);
// check whether buff object is
// an instance of Buffer class
const isItBuffer = Buffer.isBuffer(buff);
console.log(isItBuffer); // true
- The method returns boolean
true
if it is an instance ofBuffer
class andfalse
if not.