Sometimes, we want to convert string to buffer with Node.js.
In this article, we’ll look at how to convert string to buffer with Node.js.
How to convert string to buffer with Node.js?
To convert string to buffer with Node.js, we can use the Buffer.from
method.
For instance, we write
const buf = Buffer.from(bufStr, 'utf8');
to call Buffer.from
with the bufStr
string and the encoding of the string to return a buffer created from the string.
Conclusion
To convert string to buffer with Node.js, we can use the Buffer.from
method.