How to Convert ODT to DOCX using Node.js
ODT and DOCX are relatively similar files: both are based on XML and used widely for creating written content. The latter is far more popular, however, which makes converting our ODT content to DOCX a frequent necessity.
Using the ready-to-run Node.js code examples below, we can quickly & easily convert our ODT content to DOCX format with a free API request. All we need to do is follow a few quick steps below & authorize our requests with a free-tier API key, and we’ll be ready to convert our files in minutes. We can get a free-tier API key by registering a free account on the Cloudmersive website, and this will allow us to make up to 800 API calls per month with zero additional commitments.
To begin structuring our API call, let’s first install the SDK. We can do that in one of two ways — either by running the below command:
npm install cloudmersive-convert-api-client --save
Or by adding this snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Finally, we can use the below code to structure our request & make our conversion:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();
var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // 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.convertDocumentOdtToDocx(inputFile, callback);
That’s all there is to it — no more code required.