Categories
JavaScript Answers

How to convert string to buffer with Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *