doc to html

DOC to HTML conversion using Node.js.

Converting documents to using Node.js enables developers to make content more accessible, responsive, and web-ready. HTML offers great versatility for displaying text across platforms and devices, making it an ideal format for sharing and publishing Word content on the web.

In this article, we’ll show how to convert Word documents (DOC, DOCX) to HTML using the GroupDocs.Conversion Cloud SDK for Node.js, a simple and robust REST API.

REST API for DOCX to HTML Conversion

The GroupDocs.Conversion Cloud SDK for Node.js provides an efficient solution for converting Word documents to HTML format in the cloud. It handles everything from document structure and formatting to embedded elements, ensuring the HTML output mirrors the original content accurately.

🚀 Key Benefits of Using the Node.js SDK:

  • Convert DOC and DOCX to clean, responsive HTML
  • No need to install Microsoft Office
  • REST API powered – platform-independent
  • Supports saving output to cloud or downloading locally
  • OAuth 2.0 secure authorization
  • Seamlessly integrates into any Node.js app

Install the SDK via npm:

npm install groupdocs-conversion-cloud --save

Create an account on the GroupDocs Cloud Dashboard to get your Client ID and Client Secret.

Convert DOC to HTML in Node.js

Here’s how to convert Word documents to HTML using GroupDocs.Conversion Cloud SDK in a Node.js project:

  1. Initialize API configuration and instances:
const { Configuration, ConvertApi, FileApi, UploadFileRequest, ConvertDocumentRequest, ConvertSettings } = require("groupdocs-conversion-cloud");
const config = new Configuration("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
const convertApi = new ConvertApi(config);
const fileApi = new FileApi(config);
  1. Upload Word file to cloud:
const fs = require("fs");
const uploadRequest = new UploadFileRequest("input-sample.doc", fs.createReadStream("input-sample.doc"));
await fileApi.uploadFile(uploadRequest);
  1. Configure conversion settings:
const settings = new ConvertSettings();
settings.filePath = "input-sample.doc";
settings.format = "html";
settings.outputPath = "converted/output.html";
  1. Convert DOC to HTML:
const request = new ConvertDocumentRequest(settings);
const result = await convertApi.convertDocument(request);
console.log("File converted to HTML successfully.");
docx to html

Image:- A preview of DOCX to HTML conversion.

Word to HTML using cURL

You can also convert Word to HTML using a simple cURL request. First, generate a JWT token using your client credentials. Then run the following command:

curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"internal\",  \"FilePath\": \"{inputFile}\",  \"Format\": \"html\",  \"LoadOptions\": {    \"Format\": \"docx\"  },  \"OutputPath\": \"{resultantHTML}\"}"

Please replace inputFile with the name of input Word document, resultantHTML with the name of resultant HTML file and accessToken with personalized JWT access token.

To download the output HTML locally:

curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"internal\",  \"FilePath\": \"{inputFile}\",  \"Format\": \"html\",  \"LoadOptions\": {    \"Format\": \"doc\"  }}" \
-o "converted.html"

🌐 Try Our Free DOCX to HTML Converter

You can also try the free DOCX to HTML Conversion App powered by GroupDocs.Conversion Cloud.

DOCX to HTML converter

✅ Conclusion

Using GroupDocs.Conversion Cloud SDK for Node.js, converting DOC/DOCX to HTML is a breeze. Whether you choose Node.js SDK or cURL, both options offer a reliable way to make Word content browser-friendly, accessible, and responsive.

We also recommend visiting the following links to learn more about: