The Buffer.isEncoding() function tests if an encoding format is supported or not.
The Buffer.isEncoding() function accepts the encoding format as a single parameter of type string.
The Buffer.isEncoding() function returns true if the encoding format is supported; otherwise, it returns false.
The following code demonstrates how to use the Buffer.isEncoding() function in Node.js.
console.log(Buffer.isEncoding('base64'));console.log(Buffer.isEncoding('hex'));console.log(Buffer.isEncoding('utf8'));console.log(Buffer.isEncoding('ucs2'));console.log(Buffer.isEncoding('binary'));console.log(Buffer.isEncoding('utf/8'));console.log(Buffer.isEncoding('randomencoding'));
The above example illustrates that some of the supported encoding formats are base64, hex, utf8, ucs2, and binary.
Free Resources