How can I convert a number like 5 into a 4 bytes string that would resemble something like this if it were to be entered manually.
var size = "\00\00\00\05";
The number is the size of a packet I need to send through a socket and the first 4 bytes of the packet needs to be the size of the packet (without counting the first 4 bytes obviously).
var size = "\00\00\00\05";
var packet = size + "JSON_STRING";
Let me know if I'm not explaining myself properly I have never used node.js before but I'm getting the hang of it.
Bufferinstead of string.