youbetternot
youbetternot

Reputation: 2806

How can I measure a size of javascript string?

It's not recommended to send a lot of bytes between processes in Node, proven here: https://stackoverflow.com/a/27327402/2440515

Node first JSON.stringify the object. How can I actually measure a size of a string to avoid transferring to much data? Is length equal to bytes?

Upvotes: 2

Views: 3183

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161457

The easiest way is to use Buffer's helper functions.

Buffer.byteLength(str)

Upvotes: 2

Related Questions