2

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?

Community
  • 1
  • 1
youbetternot
  • 2,566
  • 2
  • 17
  • 20
  • Take in mind, it looks like on that graph that smaller packets do *better* per byte. – Brendan Dec 07 '14 at 18:54
  • possible duplicate of [String length in bytes in JavaScript](http://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript) – Kevin Kopf Dec 07 '14 at 19:07
  • The V8 engine uses UC16 (two bytes per string character) internally, but it may be converting to UTF-8 before transferring between processes since that is the more common interchange format. It would take some more specifics about how you're communicating between the two processes to look into the issue in more detail. – jfriend00 Dec 07 '14 at 19:20

1 Answers1

2

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

Buffer.byteLength(str)
loganfsmyth
  • 156,129
  • 30
  • 331
  • 251