How to convert Binary into Text String with Base 64 Encoding in Node.JS

Cloudmersive
1 min readApr 23, 2020

--

Today we will be showcasing an API designed for performing base 64 encoding upon binary, thus creating a text string. The entire process will be finished in under 5 minutes. Here we go.

Begin with the addition of this reference into your package.json, installing the client that we need.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}

Next up, our function call.

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditTextApi();var request = new CloudmersiveConvertApiClient.Base64EncodeRequest(); // Base64EncodeRequest | Input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editTextBase64Encode(request, callback);

Now we can input our binary and the API will return the encoded string. Simple as that. We also have APIs designed for detecting base 64 encoding as well as converting it back into binary.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet