I'm having trouble understanding character encoding in node.js. I'm transmitting data and for some reason the encoding causes certain characters to be replaced with other ones. What I'm doing is base 64 encoding at the client side and decoding it in node.js.
To simplify, I narrowed it down to this piece of code which fails:
new Buffer("1w==", 'base64').toString('utf8');
The 1w==
is the base 64 encoding of the ×
character. Now, when passing this string with the 'base64'
argument to a buffer and then doing .toString('utf8')
I expected to get the same character back, but I didn't. Instead I got �
(character code 65533
).
Is the encoding utf8
wrong? If so, what should I use instead? If not, how can I decode a base 64 string in node.js?