How to output Buffer content completely with console.log

zangw picture zangw · Apr 3, 2015 · Viewed 10.2k times · Source

In nodejs

console.log(new Buffer(12))

show

< Buffer 00 22 33 11 55 ...>

We know the ... ignore the following bytes. Now I want to output the whole buffer with 12 bytes, what should I do?

Answer

aleclarson picture aleclarson · Feb 17, 2018

toString('hex') works great! My example splits every 2 characters for easier visual parsing.

buf.toString('hex').match(/../g).join(' ')