How to detect if a Text String is Base 64 Encoded in Node.JS

The goal of this tutorial is simple enough: detection of base 64 encoding. We will be accomplishing this with minimal fuss through the aid of an API that already contains the necessary coding for this endeavor. All we have to do is set it up and call the base 64 detection function, simple as that.

So we start with our client setup by using npm install.

npm install cloudmersive-convert-api-client --save

The function we will need from our API will be editTextBase64Detect. To call it, use the code below.

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.Base64DetectRequest(); // Base64DetectRequest | Input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editTextBase64Detect(request, callback);

Enter your text string and the API will then proceed to tell you if it is base 64 or not. Easy!

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