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

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.

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store