-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwith-progress.js
More file actions
45 lines (38 loc) · 1.14 KB
/
with-progress.js
File metadata and controls
45 lines (38 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Conversion with progress tracking
*
* This example shows how to track upload and conversion progress.
*/
const { ConversionToolsClient } = require('conversiontools');
const apiToken = process.env.CONVERSION_TOOLS_API_TOKEN || 'your-api-token-here';
async function main() {
// Initialize client with progress callbacks
const client = new ConversionToolsClient({
apiToken,
onUploadProgress: (progress) => {
console.log(`Upload: ${progress.percent}%`);
},
onConversionProgress: (progress) => {
console.log(`Converting: ${progress.percent}% (${progress.status})`);
},
onDownloadProgress: (progress) => {
console.log(`Download: ${progress.percent}%`);
},
});
try {
console.log('Converting large JSON file to Excel...');
const outputPath = await client.convert({
type: 'convert.json_to_excel',
input: './large-data.json',
output: './result.xlsx',
options: {
excel_format: 'xlsx',
},
});
console.log(`✓ Done! File saved to: ${outputPath}`);
} catch (error) {
console.error('✗ Error:', error.message);
process.exit(1);
}
}
main();