How to convert HTML to Markdown?


I was trying to convert HTML to Markdown in Freshdesk serverless app and using “turndown”: “6.0.0” as a dependency and importing in server.js as

   var TurndownService = require('turndown');         
   var turndownService;
                        try {
                            turndownService = new TurndownService();
                        } catch (error) {
                        const markdown = turndownService.turndown(`<h1>JavaScript for Beginners</h1>`);

And I’m sending in the POST request. Locally its working fine but as a custom app its giving me error response as below

TypeError: TurndownService is not a constructor at server.js:511:43 at Object.<anonymous> (server.js:14:9) at Object.<anonymous> (/opt/nodejs/node_modules/jquery-deferred/lib/jquery-deferred.js:50:28) at fire (/opt/nodejs/node_modules/jquery-deferred/lib/jquery-callbacks.js:78:30) at Object.fireWith (/opt/nodejs/node_modules/jquery-deferred/lib/jquery-callbacks.js:188:7) at [as resolve] (/opt/nodejs/node_modules/jquery-deferred/lib/jquery-callbacks.js:195:10) at Request.handleResponse (/opt/framework/features/request.js:251:30) at Request.request (/opt/framework/features/request.js:325:14) at Request._callback (/opt/nodejs/node_modules/lodash/lodash.js:10076:25) at Request.requestRetryReply [as reply] (/opt/nodejs/node_modules/requestretry/index.js:105:19)

I used “turndown”: “6.0.0” dependency in the manifest file. I referred this from here

Please help me out if any alternative exists for this.

Thanks in advance,

Does it mean, that it will make a post request to turndownService and response of Markdown will be saved in markdown variable?

Hi @Saif I’m converting all the HTML to Markdown and sending as a body in POST request to 3rd party app(i.e., GitHub) but its failing.

var issueBody = JSON.stringify({
                    title: sub,
                    body: markdown,
                    milestone: milestone,
                    labels: arr

Here markdown is the converted HTML variable.


May I know which node version are you using?

The following error you described,

Were you able to identify which line of code is throwing this error?
Is it this one?

Yes it’s causing at catch block as a custom app. Locally its working fine. Node version is 12.14.1

Hi @soujanya,

Can you switch to Node version 10?

Also I assume that the library that you requiring is heavy. Which is why, you might be getting a TypeError as library is not completely downloaded by the time of using it.

I will initiate a Private Message on Forum Inbox to get some of your addtional details regarding the app and try increasing the serverless RAM capacity on our end to see if that is the case.

This topic was automatically closed after 14 days. New replies are no longer allowed.