How to convert Markdown MD to HTML format in Node.JS

Markdown can be a very useful tool, but oftentimes we end up with MD files in situations where they aren’t compatible. Manually converting them with the app itself is not very efficient, so we need an automated method to perform this from Node.JS. Here’s where our API comes in. With a simple function call, we can achieve this in no time. Let’s look at how to do it.

First, install the client with npm install.

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

Following that, call our conversion function.

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.ConvertWebApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertWebMdToHtml(inputFile, callback);

OK, task complete. Our MD file has been converted by the API and sent back in HTML form. And now you never have to worry about MD file problems again! We have a range of other APIs, including more that convert between different commonly used document types.

Image for post
Image for post

Written by

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