How to get a file format icon for any file type in Node.JS

File type icons are important for a properly intuitive user experience. Automating the process of retrieving the appropriate icon for a given file format can be a bit irksome, and so I have created a simple to use API that will take care of this for you. Setting up this API will take but a few minutes of your valuable time.

Add a reference to your package.json file for our API client, as seen below.

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

Now it’s time to call convertDocumentGetFileTypeIcon, which just needs the file’s extension as an input parameter, as well as optionally the desired icon size.

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.ConvertDocumentApi();var fileExtension = "fileExtension_example"; // String | Required; The file extension to be used for the icon. Limited to 4 AlphaNumeric characters.var opts = {'iconSize': 56 // Number | Optional; The desired width of the icon, preserving its aspect ratio.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDocumentGetFileTypeIcon(fileExtension, opts, callback);

Now run it and you will have your icon soon after.

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

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