This directory contains example code showing how to use the Conversion Tools Node.js client library.
-
Install the package:
npm install conversiontools
-
Get your API token from https://conversiontools.io/profile
-
Set your API token as an environment variable:
export CONVERSION_TOOLS_API_TOKEN="your-api-token-here"
-
simple-conversion.js- Simplest way to convert a filenode examples/simple-conversion.js
-
with-progress.js- Track upload and conversion progressnode examples/with-progress.js
-
sandbox-testing.js- Test conversions without using quotanode examples/sandbox-testing.js
-
advanced-manual-control.js- Full manual control over the conversion processnode examples/advanced-manual-control.js
-
url-conversion.js- Convert websites and online filesnode examples/url-conversion.js
-
typescript-example.ts- TypeScript usage with full type safetynpx tsx examples/typescript-example.ts
const { ConversionToolsClient } = require('conversiontools');
const client = new ConversionToolsClient({ apiToken: 'your-token' });
// XML to Excel
await client.convert({
type: 'convert.xml_to_excel',
input: './data.xml',
output: './result.xlsx',
});
// JSON to Excel
await client.convert({
type: 'convert.json_to_excel',
input: './data.json',
output: './result.xlsx',
});
// PDF to Text
await client.convert({
type: 'convert.pdf_to_text',
input: './document.pdf',
output: './document.txt',
});
// Excel to CSV
await client.convert({
type: 'convert.excel_to_csv',
input: './spreadsheet.xlsx',
output: './data.csv',
options: {
delimiter: 'comma',
},
});const {
ConversionToolsClient,
RateLimitError,
ValidationError,
ConversionError,
} = require('conversiontools');
try {
await client.convert({ /* ... */ });
} catch (error) {
if (error instanceof RateLimitError) {
console.error('Rate limit exceeded. Upgrade your plan.');
console.error('Limits:', error.limits);
} else if (error instanceof ValidationError) {
console.error('Invalid input:', error.message);
} else if (error instanceof ConversionError) {
console.error('Conversion failed:', error.message);
} else {
console.error('Unexpected error:', error.message);
}
}- Full API Documentation: https://conversiontools.io/api-documentation
- GitHub Repository: https://github.com/conversiontools/conversiontools-node
- Support: https://conversiontools.io/contact