{"_id":"@cubetiq/highcharts-export-server","_rev":"2-0440c8fee13e500718e579d41c620645","name":"@cubetiq/highcharts-export-server","dist-tags":{"latest":"3.0.4"},"versions":{"3.0.4":{"name":"@cubetiq/highcharts-export-server","version":"3.0.4","author":{"url":"http://www.highcharts.com/about","name":"Highsoft AS","email":"support@highcharts.com"},"license":"MIT","_id":"@cubetiq/highcharts-export-server@3.0.4","maintainers":[{"name":"vutpov","email":"vuthpov26@gmail.com"},{"name":"sombochea","email":"sombochea100@gmail.com"}],"homepage":"https://github.com/highcharts/node-export-server#readme","bugs":{"url":"https://github.com/highcharts/node-export-server/issues"},"bin":{"highcharts-export-server":"bin/cli.js"},"dist":{"shasum":"cf2f11126321fbf060c8245b223c3c4ce3cda437","tarball":"https://registry.npmjs.org/@cubetiq/highcharts-export-server/-/highcharts-export-server-3.0.4.tgz","fileCount":45,"integrity":"sha512-ajMeKmUetmwjJLmTgcm0Gr5R4KHZYxl7yyvJmFt1Leay/nD1W4l9IyCqunuKAtg5DrAzlzLjp+Ff6nHK8urzSQ==","signatures":[{"sig":"MEUCIHX/KhCuBaBcwWIF/GDa4pd5s3uh0cH6ljW0GqGQSTWqAiEAv2oBuSqIvhVbohmm3rTu8iybz/6p0AK73SqMa0IcS5c=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":711168},"main":"dist/index.esm.js","type":"module","engines":{"node":">=16.14.0"},"exports":{".":{"import":"./dist/index.esm.js","require":"./dist/index.cjs"}},"gitHead":"14a38b9c27b35191a0e4bab52d94a4d6af1e0ca1","scripts":{"lint":"eslint ./ --fix","build":"rollup -c","start":"node bin/cli.js --enableServer 1 --logLevel 2","install":"node install.js","prepare":"husky install","prestart":"rm -rf tmp && node node_modules/puppeteer/install.mjs","cli-tests":"node tests/cli/cli_test_runner.js","http-tests":"node tests/http/http_test_runner.js","node-tests":"node tests/node/node_test_runner.js","cli-tests-single":"node tests/cli/cli_test_runner_single.js","http-tests-single":"node tests/http/http_test_runner_single.js","node-tests-single":"node tests/node/node_test_runner_single.js"},"_npmUser":{"name":"sombochea","email":"sombochea100@gmail.com"},"repository":{"url":"git+https://github.com/highcharts/node-export-server.git","type":"git"},"_npmVersion":"10.1.0","description":"Convert Highcharts.JS charts to static image files.","directories":{},"lint-staged":{"*.js":"npx eslint --cache --fix","*.{js,css,md}":"npx prettier --write"},"_nodeVersion":"18.18.0","dependencies":{"cors":"^2.8.5","tarn":"^3.0.2","uuid":"^9.0.0","colors":"1.4.0","dotenv":"^16.3.1","multer":"1.4.5-lts.1","express":"^4.18.2","prompts":"^2.4.2","puppeteer":"^21.1.1","body-parser":"^1.20.2","https-proxy-agent":"^7.0.1","express-rate-limit":"^6.8.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"husky":"^8.0.3","eslint":"^8.46.0","rollup":"^3.29.4","prettier":"^3.0.0","lint-staged":"^13.2.3","eslint-plugin-import":"^2.28.0","@rollup/plugin-terser":"^0.4.4","eslint-config-prettier":"^8.9.0","eslint-plugin-prettier":"^5.0.1"},"_npmOperationalInternal":{"tmp":"tmp/highcharts-export-server_3.0.4_1702469081487_0.3153814386275182","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-12-13T12:04:41.397Z","modified":"2026-09-05T15:24:12.282Z","3.0.4":"2023-12-13T12:04:41.779Z"},"bugs":{"url":"https://github.com/highcharts/node-export-server/issues"},"author":{"url":"http://www.highcharts.com/about","name":"Highsoft AS","email":"support@highcharts.com"},"license":"MIT","homepage":"https://github.com/highcharts/node-export-server#readme","repository":{"url":"git+https://github.com/highcharts/node-export-server.git","type":"git"},"description":"Convert Highcharts.JS charts to static image files.","maintainers":[{"email":"sombochea100@gmail.com","name":"sombochea"}],"readme":"# Highcharts Node.js Export Server\n\nConvert Highcharts.JS charts to static image files.\n\n# V3.0 Notes\n\n## Upgrade notes for V3.0\n\nV3 should be a drop in replacement for V2 in most cases. However, due to changing out the browser back-end part, the various tweaks related to process handling (e.g. worker counts and so on) may have different effects than they did previously.   \n\nThe API for when using the server as a node module has changed significantly, but a compatibility layer has been created to address this. It is however recommended to change to the new API described below, as the compatibility layer is likely to be deprecated at some point in the future.\n\nOne important note is that the export server now requires `node v16.14.0` or higher.\n\n## Changelog\n\n_Fixes and enhancements:_\n\n- Replaced PhantomJS with Puppeteer\n- Updated the config handling system to optionally load JSON files, and improved environment var loading\n- Rewrote the HC caching system: it's now easier to include custom modules/depdencey lists in your own deployments\n- The install step no longer requires interaction when installing\n- Replaced the custom worker pool system with `tarn`\n- Error messages are now sent back to the client instead of being displayed in rasterized output\n- Updated NPM dependencies, removed deprecated and uneccessary dependencies\n- Lots of smaller bugfixes and tweaks\n\n_New Features:_\n\n- Added `/health` route to server to display basic server information\n- Added a UI served on `/` to perform exports from JSON configurations in browser\n\nThe full change log for all versions can be viewed [here](CHANGELOG.md).\n\n# What & Why\n\nThis is a node.js application/service that converts [Highcharts.JS](http://highcharts.com) charts to static image files. It supports PNG, JPEG, SVG, and PDF output; and the input can be either SVG, or JSON-formatted chart options.\n\nThe application can be used either as a CLI (Command Line Interface), as an HTTP server, or as a node.js module.\n\n## Use Cases\n\nThe main use case for the export server is situations where headless conversion of charts are required. Common use cases include automatic report generation, static caching, and for including charts in e.g. presentations, or other documents.\n\nIn addition, the HTTP mode can be used to run your own export server for your users, rather than relying on the public export.highcharts.com server which is rate limited.\n\nThe HTTP server can either be ran stand-alone and integrate with your other applications and services, or it can be ran in such a way that the export buttons on your charts route to your own server.\n\nTo do latter, add:\n\n```\n{\n  exporting: {\n    url: \"<IP to the self-hosted export server>\"\n  }\n}\n```\n\nto the chart options when creating your charts.\n\nFor systems that generate automatic reports, using the export server as a node.js module is a great fit - especially if your report generator is also written in node. See [here](https://github.com/highcharts/node-export-server#using-as-a-nodejs-module) for examples.\n\n# Install\n\nFirst, make sure you have node.js installed. Go to [nodejs.org](https://nodejs.org/en/download/) and download/install node for your platform.\n\nAfter node.js is installed, install the export server by opening a terminal and typing:\n\n```\nnpm install highcharts-export-server -g\n```\n\nOR:\n\n```\ngit clone https://github.com/highcharts/node-export-server\nnpm install\nnpm link\n```\n\nNote: depending on how you installed Node, you may have to create a symlink from `nodejs` to `node`. Example on Linux:\n\n```\nln -s `which nodejs` /usr/bin/node\n```\n\n# Running\n\n```\nhighcharts-export-server <arguments>\n```\n\n# Configuration\n\nThere are four main ways of loading configurations:\n\n- By loading default options from the `lib/schemas/config.js` file.\n- By loading a custom JSON file.\n- By providing environment variables.\n- By passing command line arguments.\n\n...or any combination of the four. In this case, the options from the later step take precedence (config file -> custom json -> envs -> cli arguments).\n\n## Loading Default JSON Config\n\nThe below JSON presents the default config that resides in the `lib/schemas/config.js` file. If no `.env` file is found (more on `.env` and environment variables below), these options are used.\n\nThe format, with its default values are as follows (using the below ordering of core scripts and modules is recommended):\n\n```\n{\n  \"puppeteer\": {\n    \"args\": []\n  },\n  \"highcharts\": {\n    \"version\": \"latest\",\n    \"cdnURL\": \"https://code.highcharts.com/\",\n    \"coreScripts\": [\n      \"highcharts\",\n      \"highcharts-more\",\n      \"highcharts-3d\"\n    ],\n    \"modules\": [\n      \"stock\",\n      \"map\",\n      \"gantt\",\n      \"exporting\",\n      \"export-data\",\n      \"parallel-coordinates\",\n      \"accessibility\",\n      \"annotations-advanced\",\n      \"boost-canvas\",\n      \"boost\",\n      \"data\",\n      \"draggable-points\",\n      \"static-scale\",\n      \"broken-axis\",\n      \"heatmap\",\n      \"tilemap\",\n      \"timeline\",\n      \"treemap\",\n      \"item-series\",\n      \"drilldown\",\n      \"histogram-bellcurve\",\n      \"bullet\",\n      \"funnel\",\n      \"funnel3d\",\n      \"pyramid3d\",\n      \"networkgraph\",\n      \"pareto\",\n      \"pattern-fill\",\n      \"pictorial\",\n      \"price-indicator\",\n      \"sankey\",\n      \"arc-diagram\",\n      \"dependency-wheel\",\n      \"series-label\",\n      \"solid-gauge\",\n      \"sonification\",\n      \"stock-tools\",\n      \"streamgraph\",\n      \"sunburst\",\n      \"variable-pie\",\n      \"variwide\",\n      \"vector\",\n      \"venn\",\n      \"windbarb\",\n      \"wordcloud\",\n      \"xrange\",\n      \"no-data-to-display\",\n      \"drag-panes\",\n      \"debugger\",\n      \"dumbbell\",\n      \"lollipop\",\n      \"cylinder\",\n      \"organization\",\n      \"dotplot\",\n      \"marker-clusters\",\n      \"hollowcandlestick\",\n      \"heikinashi\"\n    ],\n    \"indicators\": [\n      \"indicators-all\"\n    ],\n    \"scripts\": [\n      \"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js\"\n    ],\n    \"forceFetch\": false\n  },\n  \"export\": {\n    \"infile\": false,\n    \"instr\": false,\n    \"options\": false,\n    \"outfile\": false,\n    \"type\": \"png\",\n    \"constr\": \"chart\",\n    \"height\": 400,\n    \"width\": 600,\n    \"scale\": 1,\n    \"globalOptions\": false,\n    \"themeOptions\": false,\n    \"batch\": false\n  },\n  \"customCode\": {\n    \"allowCodeExecution\": false,\n    \"allowFileResources\": true,\n    \"customCode\": false,\n    \"callback\": false,\n    \"resources\": false,\n    \"loadConfig\": false,\n    \"createConfig\": false\n  },\n  \"server\": {\n    \"enable\": false,\n    \"host\": \"0.0.0.0\",\n    \"port\": 7801,\n    \"ssl\": {\n      \"enable\": false,\n      \"force\": false,\n      \"port\": 443,\n      \"certPath\": \"\"\n    },\n    \"rateLimiting\": {\n      \"enable\": false,\n      \"maxRequests\": 10,\n      \"skipKey\": \"\",\n      \"skipToken\": \"\"\n    }\n  },\n  \"pool\": {\n    \"initialWorkers\": 4,\n    \"maxWorkers\": 8,\n    \"workLimit\": 40,\n    \"queueSize\": 5,\n    \"timeoutThreshold\": 5000,\n    \"acquireTimeout\": 5000,\n    \"reaper\": true,\n    \"benchmarking\": false,\n    \"listenToProcessExits\": true\n  },\n  \"logging\": {\n    \"level\": 4,\n    \"file\": \"highcharts-export-server.log\",\n    \"dest\": \"log/\"\n  },\n  \"ui\": {\n    \"enable\": false,\n    \"route\": \"/\"\n  },\n  \"other\": {\n    \"noLogo\": false\n  }\n}\n```\n\n## Loading Custom JSON Config\n\nLoading an additional JSON configuration file can be done by using the `--loadConfig <filepath>` option. Such a JSON can be created manually or through a prompt called by the `--createConfig` option.\n\n## Environment Variables\n\nThese are set as variables in your environment. They take precedence over options from the `lib/schemas/config.js` file. On Linux, use e.g. `export`.\n\n### Export config\n- `EXPORT_DEFAULT_TYPE`: The format of the file to export to. Can be jpeg, png, pdf or svg.\n- `EXPORT_DEFAULT_CONSTR`: The constructor to use. Can be chart, stockChart, mapChart or ganttChart.\n- `EXPORT_DEFAULT_HEIGHT`: The height of the exported chart. Overrides the option in the chart settings.\n- `EXPORT_DEFAULT_WIDTH`: The width of the exported chart. Overrides the option in the chart settings.\n- `EXPORT_DEFAULT_SCALE`: The scale of the exported chart. Ranges between 0.1 and 5.0.\n\n### Highcharts config\n- `HIGHCHARTS_VERSION`: Highcharts version to use.\n- `HIGHCHARTS_CDN`: The CDN URL of Highcharts scripts to use.\n- `HIGHCHARTS_CORE_SCRIPTS`: Highcharts core scripts to fetch.\n- `HIGHCHARTS_MODULES`: Highcharts modules to fetch.\n- `HIGHCHARTS_INDICATORS`: Highcharts indicators to fetch.\n- `HIGHCHARTS_FORCE_FETCH`: Should refetch all the scripts after each server rerun.\n\n### Custom code config\n- `HIGHCHARTS_ALLOW_CODE_EXECUTION`: If set to true, allow for the execution of arbitrary code when exporting.\n- `HIGHCHARTS_ALLOW_FILE_RESOURCES`: Allow injecting resources from the filesystem. Has no effect when running as a server.\n\n### Server config\n- `HIGHCHARTS_SERVER_ENABLE`: If set to true, starts a server on 0.0.0.0.\n- `HIGHCHARTS_SERVER_HOST`: The hostname of the server. Also starts a server listening on the supplied hostname.\n- `HIGHCHARTS_SERVER_PORT`: The port to use for the server. Defaults to 7801.\n\n### Server SSL config\n- `HIGHCHARTS_SERVER_SSL_ENABLE`: Enables the SSL protocol.\n- `HIGHCHARTS_SERVER_SSL_FORCE`: If set to true, forces the server to only serve over HTTPS.\n- `HIGHCHARTS_SERVER_SSL_PORT`: The port on which to run the SSL server.\n- `HIGHCHARTS_SERVER_SSL_CERT_PATH`: The path to the SSL certificate/key.\n\n### Server rate limiting config\n- `HIGHCHARTS_RATE_LIMIT_ENABLE`: Enables rate limiting.\n- `HIGHCHARTS_RATE_LIMIT_MAX`: Max requests allowed in a one minute.\n- `HIGHCHARTS_RATE_LIMIT_WINDOW`: The time window in minutes for rate limiting.\n- `HIGHCHARTS_RATE_LIMIT_DELAY`: The amount to delay each successive request before hitting the max.\n- `HIGHCHARTS_RATE_LIMIT_TRUST_PROXY`: Set this to true if behind a load balancer.\n- `HIGHCHARTS_RATE_LIMIT_SKIP_KEY`: Allows bypassing the rate limiter and should be provided with skipToken argument.\n- `HIGHCHARTS_RATE_LIMIT_SKIP_TOKEN`: Allows bypassing the rate limiter and should be provided with skipKey argument.\n\n### Pool config\n- `HIGHCHARTS_POOL_MIN_WORKERS`: The number of initial workers to spawn.\n- `HIGHCHARTS_POOL_MAX_WORKERS`: The number of max workers to spawn.\n- `HIGHCHARTS_POOL_WORK_LIMIT`: The pieces of work that can be performed before restarting process.\n- `HIGHCHARTS_POOL_QUEUE_SIZE`: The size of the request overflow queue.\n- `HIGHCHARTS_POOL_TIMEOUT`: The number of milliseconds before timing out.\n- `HIGHCHARTS_POOL_ACQUIRE_TIMEOUT`: The number of milliseconds to wait for acquiring a resource.\n- `HIGHCHARTS_POOL_ENABLE_REAPER`: Whether or not to evict workers after a certain time period.\n- `HIGHCHARTS_POOL_BENCHMARKING`: Enable benchmarking.\n- `HIGHCHARTS_POOL_LISTEN_TO_PROCESS_EXITS`: Set to false in order to skip attaching process.exit handlers.\n\n### Logging config\n- `HIGHCHARTS_LOG_LEVEL`: The log level (0: silent, 1: error, 2: warning, 3: notice, 4: verbose).\n- `HIGHCHARTS_LOG_FILE`: A name of a log file. The --logDest also needs to be set to enable file logging.\n- `HIGHCHARTS_LOG_DEST`: The path to store log files. Also enables file logging.\n\n### UI config\n- `HIGHCHARTS_UI_ENABLE`: Enables the UI for the export server.\n- `HIGHCHARTS_UI_ROUTE`: The route to attach the UI to.\n\n### Other config\n- `HIGHCHARTS_NO_LOGO`: Skip printing the logo on a startup. Will be replaced by a simple text.\n\n### Proxy config\n- `PROXY_SERVER_HOST`: The host of the proxy server to use if exists.\n- `PROXY_SERVER_PORT`: The port of the proxy server to use if exists.\n- `PROXY_SERVER_TIMEOUT`: The timeout for the proxy server to use if exists.\n\n## Command Line Arguments\n\nTo supply command line arguments, add them as flags when running the application:\n`highcharts-export-server --flag1 value --flag2 value ...`\n\n_Available options:_\n\n- `--infile`: The input file name along with a type (json or svg). It can be a correct JSON or SVG file (defaults to `false`).\n- `--instr`: An input in a form of a stringified JSON or SVG file. Overrides the --infile (defaults to `false`).\n- `--options`: An alias for the --instr option (defaults to `false`).\n- `--outfile`: The output filename along with a type (jpeg, png, pdf or svg). Ignores the --type flag (defaults to `false`).\n- `--type`: The format of the file to export to. Can be jpeg, png, pdf or svg (defaults to `png`).\n- `--constr`: The constructor to use. Can be chart, stockChart, mapChart or ganttChart (defaults to `chart`).\n- `--height`: The height of the exported chart. Overrides the option in the chart settings (defaults to `600`).\n- `--width`: The width of the exported chart. Overrides the option in the chart settings (defaults to `400`).\n- `--scale`: The scale of the exported chart. Ranges between 0.1 and 5.0 (defaults to `1`).\n- `--globalOptions`: A stringified JSON or a filename with options to be passed into the Highcharts.setOptions (defaults to `false`).\n- `--themeOptions`: A stringified JSON or a filename with theme options to be passed into the Highcharts.setOptions (defaults to `false`).\n- `--batch`: Starts a batch job. A string that contains input/output pairs: \"in=out;in=out;..\" (defaults to `false`).\n- `--allowCodeExecution`: If set to true, allow for the execution of arbitrary code when exporting (defaults to `false`).\n- `--allowFileResources`: Allow injecting resources from the filesystem. Has no effect when running as a server (defaults to `true`).\n- `--customCode`: Custom code to be called before chart initialization. Can be a function, a code that will be wrapped within a function or a filename with the js extension (defaults to `false`).\n- `--callback`: A JavaScript function to run on construction. Can be a function or a filename with the js extension (defaults to `false`).\n- `--resources`: An additional resource in a form of stringified JSON. It can contains files, js and css sections (defaults to `false`).\n- `--loadConfig`: A file that contains a pre-defined config to use (defaults to `false`).\n- `--createConfig`: Allows to set options through a prompt and save in a provided config file (defaults to `false`).\n- `--enableServer`: If set to true, starts a server on 0.0.0.0 (defaults to `false`).\n- `--host`: The hostname of the server. Also starts a server listening on the supplied hostname (defaults to `0.0.0.0`).\n- `--port`: The port to use for the server. Defaults to 7801 (defaults to `7801`).\n- `--enableSsl`: Enables the SSL protocol (defaults to `false`).\n- `--sslForced`: If set to true, forces the server to only serve over HTTPS (defaults to `false`).\n- `--sslPort`: The port on which to run the SSL server (defaults to `443`).\n- `--certPath`: The path to the SSL certificate/key (defaults to ``).\n- `--enableRateLimiting`: Enables rate limiting (defaults to `false`).\n- `--maxRequests`: Max requests allowed in a one minute (defaults to `10`).\n- `--skipKey`: Allows bypassing the rate limiter and should be provided with skipToken argument (defaults to ``).\n- `--skipToken`: Allows bypassing the rate limiter and should be provided with skipKey argument (defaults to ``).\n- `--initialWorkers`: The number of initial workers to spawn (defaults to `4`).\n- `--maxWorkers`: The number of max workers to spawn (defaults to `4`).\n- `--workLimit`: The pieces of work that can be performed before restarting process (defaults to `60`).\n- `--queueSize`: The size of the request overflow queue (defaults to `5`).\n- `--timeoutThreshold`: The number of milliseconds before timing out (defaults to `5000`).\n- `--acquireTimeout`: The number of milliseconds to wait for acquiring a resource (defaults to `5000`).\n- `--reaper`: Whether or not to evict workers after a certain time period (defaults to `true`).\n- `--benchmarking`: Enable benchmarking (defaults to `true`).\n- `--listenToProcessExits`: Set to false in order to skip attaching process.exit handlers (defaults to `true`).\n- `--logLevel`: The log level (0: silent, 1: error, 2: warning, 3: notice, 4: verbose) (defaults to `4`).\n- `--logFile`: A name of a log file. The --logDest also needs to be set to enable file logging (defaults to `highcharts-export-server.log`).\n- `--logDest`: The path to store log files. Also enables file logging (defaults to `log/`).\n- `--enableUi`: Enables the UI for the export server (defaults to `false`).\n- `--uiRoute`: The route to attach the UI to (defaults to `/`).\n- `--noLogo`: Skip printing the logo on a startup. Will be replaced by a simple text (defaults to `false`).\n\n# Tips, Tricks & Notes\n\n## Note about chart size\n\nThe `width` argument is mostly to set a zoom factor rather than an absolute width.\n\nIf you need to set the _height_ of the chart, it can be done in two ways:\n\n- Set it in the chart config under [`chart.height`](https://api.highcharts.com/highcharts/chart.height).\n- Set it in the chart config under [`exporting.sourceHeight`](https://api.highcharts.com/highcharts/exporting.sourceHeight).\n\nThe latter is prefered, as it lets you set a separate sizing when exporting and when displaying the chart in your web page.\n\nLike previously mentioned, there are multiple ways to set and prioritize options, and the `height`, `width` and `scale` are no exceptions here. The priority goes like this:\n\n1. Options from the `export` section of the provided options (CLI, JSON, etc.).\n2. The `sourceHeight`, `sourceWidth` and `scale` from the `chart.exporting` section of chart's Highcharts options.\n3. The `height` and `width` from the `chart` section of chart's Highcharts options.\n4. The `sourceHeight`, `sourceWidth` and `scale` from the `chart.exporting` section of chart's Highcharts global options, if provided.\n5. The `height` and `width` from the `chart` section of chart's Highcharts global options, if provided.\n6. If no options are found to this point, the default values will be used (`height = 400`, `width = 600` and `scale = 1`).\n\n## Note about process.exit listeners\n\nThe export server attaches event listeners to process.exit. This is to make sure that there are no memory leaks or zombie processes if the application is unexpectedly terminated.\n\nListeners are also attached to uncaught exceptions - if one appears, the entire pool is killed, and the application terminated.\n\nIf you do not want this behavior, start the server with `--listenToProcessExits 0`.\n\nBe aware though - if you disable this and you don't take great care to manually kill the pool, your server _will_ bleed memory when the app is terminated.\n\n## Note About Resources and the CLI\n\nIf `--resources` is not set, and a file `resources.json` exist in the folder from which the cli tool was ran, it will use the `resources.json` file.\n\n## Note on Worker Count & Work Limit\n\nThe export server utilizes a pool of _workers_, where each worker is a Puppeteer process (browser instance's page) responsible for the actual chart rasterization. The pool size can be set with the `--initialWorkers` and `--maxWorkers` options, and should be tweaked to fit the hardware on which you're running the server. \n\nIt's recommended that you start with the default (4), and work your way up (or down if 8 is too many for your setup, and things are unstable) gradually. The `tests/other/stress-test.js` script can be used to test the server and expects the server to be running on port 7801.\n\nEach of the workers has a maximum number of requests it can handle before it restarts itself to keep everything responsive. This number is 40 by default, and can be tweaked with `--workLimit`. As with `--initialWorkers` and `--maxWorkers`, this number should also be tweaked to fit your use case. Also, the `--acquireTimeout` option is worth to mention as well, in case there would be problems with acquiring resources. It is set in miliseconds with 5000 as a default value.\n\n## Setup: Injecting the Highcharts dependency\n\nIn order to use the export server, Highcharts.js needs to be injected into the export template.\n\nSince version 3.0.0 Highcharts is fetched in a Just-In-Time manner, which makes it easy to switch configurations. It is no longer required to explicitly accept the license as in older versions - __but the export server still requires a valid Highcharts license to be used__.\n\n## Using In Automated Deployments\n\nSince version 3.0.0, when using in automated deployments, the configuration can either be loaded using environment variables or a JSON configuration file.\n\nFor a reference on available variables, refer to the configuration section above.\n\nIf you're using the export server as a dependency in your own app, depending on your setup, it may be possible to set the env variable in your `package.json` file:\n\n```\n{\n  \"scripts\": {\n    \"preinstall\": \"export <setting>=<value>\"\n  }\n}\n```\n\n_Library fetches_\n\nWhen fetching the built Highcharts library, the default behaviour is to fetch them from `code.highcharts.com`.\n\n## HTTP Server\n\nThe server accepts the following arguments in a POST body:\n\n- `infile`: A string containing JSON or SVG for the chart.\n- `options`: Alias for `infile`.\n- `svg`: A string containing SVG to render.\n- `type`: The format: `png`, `jpeg`, `pdf`, `svg`. Mimetypes can also be used.\n- `scale`: The scale factor. Use it to improve resolution in PNG and JPEG, for example setting scale to 2 on a 600px chart will result in a 1200px output.\n- `height`: The chart height.\n- `width`: The chart width.\n- `callback`: Javascript to execute in the highcharts constructor.\n- `resources`: Additional resources.\n- `constr`: The constructor to use. Either `chart`, `stockChart`, `mapChart` or `ganttChart`.\n- `b64`: Bool, set to true to get base64 back instead of binary.\n- `noDownload`: Bool, set to true to not send attachment headers on the response.\n- `globalOptions`: A JSON object with options to be passed to `Highcharts.setOptions`.\n- `themeOptions`: A JSON object with options to be passed to `Highcharts.setOptions`.\n- `customCode`: Custom code to be called before chart initialization. Can be a function, a code that will be wrapped within a function or a filename with the js extension.\n\nIt responds to `application/json`, `multipart/form-data`, and URL encoded requests.\n\nCORS is enabled for the server.\n\nIt's recommended to run the server using [pm2](https://www.npmjs.com/package/pm2) unless running in a managed environment/container. Please refer to the pm2 documentation for details on how to set this up.\n\n## SSL\n\nTo enable SSL support, add `--certPath <path to key/crt>` when running the server. Note that the certificate files needs to be named as such:\n\n- `server.crt`\n- `server.key`\n\n## System Requirements\n\nThe system requirements largely depend on your use case.\n\nThe application is largely CPU and memory bound, so when using in heavy-traffic situations, it needs a fairly beefy server. It's recommended that the server has at least 1GB of memory regardless of traffic, and more than one core.\n\n## Installing Fonts\n\nDoes your Linux server not have Arial or Calibri? Puppeteer uses the system installed fonts to render pages. Therefore the Highcharts Export Server requires fonts to be properly installed on the system in order to use them to render charts.\n\nNote that the default font-family config in Highcharts is `\"Lucida Grande\", \"Lucida Sans Unicode\", Verdana, Arial, Helvetica, sans-serif\"`.\n\nFonts are installed differently depending on your system. Please follow the below guides for font installation on most common systems.\n\n### OS X\n\nInstall your desired fonts with the Font Book app, or place it in /Library/Fonts/ (system) or ~/Library/Fonts/ (user).\n\n### Linux\n\nCopy or move the TTF file to the `/usr/share/fonts/truetype` (may require sudo privileges):\n\n```\nmkdir -p /usr/share/fonts/truetype\ncp yourFont.ttf /usr/share/fonts/truetype/\nfc-cache -fv\n```\n\n### Windows\n\nCopy or move the TTF file to `C:\\Windows\\Fonts\\`:\n\n```\ncopy yourFont.ttf C:\\Windows\\Fonts\\yourFont.ttf\n```\n\n### Google fonts\n\nIf you need Google Fonts in your custom installation, they can be had here: https://github.com/google/fonts.\n\nDownload them, and follow the above instructions for your OS.\n\n## Server Test\n\nRun the below in a terminal after running `highcharts-export-server --enableServer 1`:\n\n```\n# Generate a chart and save it to mychart.png\ncurl -H \"Content-Type: application/json\" -X POST -d '{\"infile\":{\"title\": {\"text\": \"Steep Chart\"}, \"xAxis\": {\"categories\": [\"Jan\", \"Feb\", \"Mar\"]}, \"series\": [{\"data\": [29.9, 71.5, 106.4]}]}}' 127.0.0.1:7801 -o mychart.png\n```\n\n# Using as a Node.js Module\n\nThe export server can also be used as a node module to simplify integrations:\n\n```\n// Import the Export Server module\nconst exporter = require('highcharts-export-server');\n\n// Initialize export settings with your chart's config\n// Export settings correspond to the available CLI arguments described above.\nconst exportSettings = {\n  export: {\n    type: 'png',\n    options: {\n      title: {\n        text: 'My Chart'\n      },\n      xAxis: {\n        categories: [\"Jan\", \"Feb\", \"Mar\", \"Apr\"]\n      },\n      series: [\n        {\n          type: 'line',\n          data: [1, 3, 2, 4]\n        },\n        {\n          type: 'line',\n          data: [5, 3, 4, 2]\n        }\n      ]\n    }\n  }\n};\n\n// Set the new options and merge it with the default options\nconst options = exporter.setOptions(exportSettings);\n\n// Initialize a pool of workers\nawait exporter.initPool(options);\n\n// Perform an export\nexporter.startExport(exportSettings, function (res, err) {\n  // The export result is now in res.\n  // It will be base64 encoded (res.data).\n\n  // Kill the pool when we're done with it.\n  exporter.killPool();\n});\n```\n\n## CommonJS support\nThis package supports both CommonJS and ES modules.\n\n## Node.js API Reference\n\n**highcharts-export-server module**\n\n### Functions\n\n- `log(level, ...)`: Log something. Level is a number from 1 to 4. Args are joined by whitespace to form the message.\n\n- `mapToNewConfig(oldOptions)`: Maps the old options structure (for the PhantomJS server) to the new config structure.\n\n- `setOptions(userOptions, args)`: Initializes and sets the general options for the server instace, keeping the principle of the options load priority (more in the Configuration section). It accepts optional userOptions and with args from the CLI.\n\n- `startExport(settings, endCallback)`: Start an export process. The `settings` contains final options gathered from all possible sources (config, env, cli, json). The `endCallback` is called when the export is completed, with an object as the first argument containing the base64 respresentation of a chart.\n\n- `startServer({serverConfig, uiConfig})`: Start an http server on the given port. The `serverConfig` object contains all server and `uiConfig` object contains all ui related properties (see the `server` and `ui` section in the `lib/schemas/config.js` file for a reference).\n\n- `server` - The server instance:\n  - `startServer({serverConfig, uiConfig})` - The same as `startServer` from above.\n  - `getExpress()` - Return the express module instance.\n  - `getApp()` - Return the app instance.\n  - `use(path, ...middlewares)` - Add a middleware to the server.\n  - `get(path, ...middlewares)` - Add a get middleware to the server.\n  - `post(path, ...middlewares)` - Add a post middleware to the server.\n  - `enableRateLimiting(options)` - Enable rate limiting on the POST path.\n    - `maxRequests` - The maximum amount of requests before rate limiting kicks in.\n    - `window` - The time window in minutes for rate limiting. Example: setting `window` to `1` and `max` to `30` will allow a maximum of 30 requests within one minute.\n    - `delay` - The amount to delay each successive request before hitting the max.\n    - `trustProxy` - Set this to true if behind a load balancer.\n    - `skipKey`/`skipToken` - key/token pair that allows bypassing the rate limiter. On requests, these should be sent as such: `?key=<key>&access_token=<token>`.\n\n- `initPool(options)`: Init the pool of Puppeteer browser's pages - must be done prior to exporting. The `options` is an object that contains all options with, among others, the `pool` section which is required to successfuly init the pool:\n  - `initialWorkers` (default 4) - Initial worker process count.\n  - `maxWorkers` (default 8) - Max worker processes count.\n  - `workLimit` (default 40) - How many task can be performed by a worker process before it's automatically restarted.\n  - `timeoutThreshold` (default 3500) - The maximum allowed time for each export job execution, in milliseconds. If a worker has been executing a job for longer than this period, it will be restarted.\n  - `acquireTimeout` (default 3000) - the maximum allowed time for each resource acquire, in milliseconds.\n  - `benchmarking` (default false) - Enable benchmarking.\n  - `listenToProcessExits` (default true) - Set to false in order to skip attaching process.exit handlers.\n\n- `killPool()`: Kill the pool of resources (Puppeteer browser's pages).\n\n# Performance Notice\n\nIn cases of batch exports, it's faster to use the HTTP server than the CLI. This is due to the overhead of starting Puppeteer for each job when using the CLI.\n\nAs a concrete example, running the CLI with [testcharts/basic.json](testcharts/basic.json) as the input and converting to PNG averages about 449ms. Posting the same configuration to the HTTP server averages less than 100ms.\n\nSo it's better to write a bash script that starts the server and then performs a set of POSTS to it through e.g. curl if not wanting to host the export server as a service.\n\nAlternatively, you can use the `--batch` switch if the output format is the same for each of the input files to process:\n\n```\nhighcharts-export-server --batch \"infile1.json=outfile1.png;infile2.json=outfile2.png;...\"\n```\n\nOther switches can be combined with this switch.\n\n# Switching HC version at runtime\n\nIf `HIGHCHARTS_ADMIN_TOKEN` is set, you can use the `POST /change_hc_version/:newVersion` route to switch the Highcharts version on the server at runtime, ie. without restarting or redeploying the application.\n\nA sample request to change the version to 10.3.3 is as follows:\n\n```\ncurl -H 'hc-auth: <YOUR AUTH TOKEN>' -X POST <SERVER URL>/change_hc_version/10.3.3\n```\n\ne.g.\n\n```\ncurl -H 'hc-auth: 12345' -X POST 127.0.0.1:7801/change_hc_version/10.3.3\n```\n\nThis is useful to e.g. upgrade to the latest HC version without downtime.\n\n# License\n\n[MIT](LICENSE). Note that a valid Highcharts License is also required to do exports.\n","readmeFilename":"README.md"}