I have an express server written in typescript.
As atob()
or btoa()
works on browsers, on Nodejs.
We generally use
Buffer.from("some-string").toString('base64')
to encode string to base64.
However, this doesn't seem to work when I am writing the code in TypeScript. I need some help with this.
Buffer. from("some-string"). toString('base64') to encode string to base64.
To decode with base64 you need to use the --decode flag. With encoded string, you can pipe an echo command into base64 as you did to encode it. Using the example encoding shown above, let's decode it back into its original form. Provided your encoding was not corrupted the output should be your original string.
Base64 encoding and decoding can be done in Node. js using the Buffer object. Encoding the original string to base64: The Buffer class in Node. js can be used to convert a string to a series of bytes.
To convert a string into a Base64 character the following steps should be followed: Get the ASCII value of each character in the string. Compute the 8-bit binary equivalent of the ASCII values. Convert the 8-bit characters chunk into chunks of 6 bits by re-grouping the digits.
Please Use btoa for encode string
console.log(btoa("abc")); // YWJj
use for atob decode the same string
console.log(atob("YWJj")); // abc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With