I want to ask about the Highchart export server till node 14 our export server was working when i updated node 14 to 20 latest version my export highchart export stopped working. I have tried out different things but none of them works can anyone help me. i use all verions of high chart export server with node 20 but no result chart not draw.
Highchart export server 3.0.5
I find the solution by adding in package.js
"exports": {
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs"
}
},
"repository": {
"url": "https://github.com/highcharts/node-export-server",
"type": "git"
},
"bin": {
"highcharts-export-server": "./bin/cli.js"
},
"scripts": {
"install": "node install.js",
"start": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
in node.js file
let exporter = require('highcharts-export-server');
exporter.killPool();
if not work then add .env file and past the below code.
# Export config
EXPORT_DEFAULT_TYPE = png
EXPORT_DEFAULT_CONSTR = chart
EXPORT_DEFAULT_HEIGHT = 400
EXPORT_DEFAULT_WIDTH = 600
EXPORT_DEFAULT_SCALE = 1
EXPORT_RASTERIZATION_TIMEOUT = 1500
# Highcharts config
HIGHCHARTS_VERSION = latest
HIGHCHARTS_CDN = https://code.highcharts.com/
HIGHCHARTS_FORCE_FETCH = false
HIGHCHARTS_CORE_SCRIPTS =
HIGHCHARTS_MODULES =
HIGHCHARTS_INDICATORS =
# Custom code config
HIGHCHARTS_ALLOW_CODE_EXECUTION = false
HIGHCHARTS_ALLOW_FILE_RESOURCES = false
# Server config
HIGHCHARTS_SERVER_ENABLE = false
HIGHCHARTS_SERVER_HOST = 0.0.0.0
HIGHCHARTS_SERVER_PORT = 7801
# Server SSL config
HIGHCHARTS_SERVER_SSL_ENABLE = false
HIGHCHARTS_SERVER_SSL_FORCE = false
HIGHCHARTS_SERVER_SSL_PORT = 443
HIGHCHARTS_SERVER_SSL_CERT_PATH =
# Server rate limiting config
HIGHCHARTS_RATE_LIMIT_ENABLE = false
HIGHCHARTS_RATE_LIMIT_MAX = 10
HIGHCHARTS_RATE_LIMIT_WINDOW = false
HIGHCHARTS_RATE_LIMIT_DELAY = 0
HIGHCHARTS_RATE_LIMIT_TRUST_PROXY = false
HIGHCHARTS_RATE_LIMIT_SKIP_KEY =
HIGHCHARTS_RATE_LIMIT_SKIP_TOKEN =
# Pool config
HIGHCHARTS_POOL_MIN_WORKERS = 8
HIGHCHARTS_POOL_MAX_WORKERS = 8
HIGHCHARTS_POOL_WORK_LIMIT = 40
HIGHCHARTS_POOL_ACQUIRE_TIMEOUT = 5000
HIGHCHARTS_POOL_CREATE_TIMEOUT = 5000
HIGHCHARTS_POOL_DESTROY_TIMEOUT = 5000
HIGHCHARTS_POOL_IDLE_TIMEOUT = 30000
HIGHCHARTS_POOL_CREATE_RETRY_INTERVAL = 200
HIGHCHARTS_POOL_REAPER_INTERVAL = 1000
HIGHCHARTS_POOL_BENCHMARKING = false
HIGHCHARTS_POOL_LISTEN_TO_PROCESS_EXITS = true
# Logging config
HIGHCHARTS_LOG_LEVEL = 4
HIGHCHARTS_LOG_FILE = highcharts-export-server.log
HIGHCHARTS_LOG_DEST = log/
# UI config
HIGHCHARTS_UI_ENABLE = true
HIGHCHARTS_UI_ROUTE = /
# Other config
HIGHCHARTS_NO_LOGO = false
# Proxy config
PROXY_SERVER_HOST =
PROXY_SERVER_PORT =
PROXY_SERVER_TIMEOUT =
Then the index file with
const Hapi = require('@hapi/hapi');
const exporter = require('highcharts-export-server');
const fs = require('fs');
exporter.killPool();
const init = async () => {
const server = Hapi.server({
port: 3000,
host: 'localhost',
});
server.route({
method: 'GET',
path: '/export-chart',
handler: async (request, h) => {
const exportSettings = {
export: {
type: 'pdf',
options: {
title: {
text: 'My Chart',
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr'],
},
series: [
{
type: 'bar',
data: [1, 3, 2, 4],
},
{
type: 'line',
data: [5, 3, 4, 2],
},
],
},
},
};
// Set the new options and merge it with the default options
const options = exporter.setOptions(exportSettings);
try {
await exporter.initPool(options);
exporter.startExport(exportSettings, async function (res, err) {
if (err) {
console.log(err);
return h.response('Error exporting chart').code(500);
}
// Save the PDF file locally
const outputFile = 'downloads/exported-chart3.pdf';
fs.writeFileSync(outputFile, Buffer.from(res.data, 'base64'));
console.log(`PDF file saved as: ${outputFile}`);
return h.response(`PDF file saved as: ${outputFile}`);
});
} catch (error) {
console.error(error);
return h.response('Internal Server Error').code(500);
}
return "File save successfully.;"
},
});
await server.start();
console.log('Server running on %s', server.info.uri);
};
process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});
init();
this the working example for me.