{"id":4824,"date":"2016-05-05T20:39:26","date_gmt":"2016-05-05T20:39:26","guid":{"rendered":"http:\/\/www.highcharts.com\/blog\/?p=4824"},"modified":"2026-01-08T09:42:23","modified_gmt":"2026-01-08T09:42:23","slug":"188-highcharts-optimized-for-npm","status":"publish","type":"post","link":"https:\/\/www.highcharts.com\/blog\/news\/188-highcharts-optimized-for-npm\/","title":{"rendered":"Highcharts optimized for npm"},"content":{"rendered":"<p>We are happy to announce that Highcharts since version 4.1.10 supports the CommonJS module pattern out of the box. Which means that all our distribution files are now available to load properly in CommonJS environments like <a href=\"http:\/\/nodejs.org\/en\/\">Node.js<\/a>.<\/p>\n<p>In a CommonJS environment, the Highcharts variable will be assigned to <code>module.exports<\/code> instead of being set globally. This is a best practice to avoid polluting the global namespace. If by any chance you would like to use Highcharts as a global variable, you must set it yourself. This applies only to CommonJS environments.<\/p>\n<p>To learn more about how to set up Highcharts and its different modules with npm, see\u00a0<a href=\"https:\/\/www.highcharts.com\/docs\/getting-started\/install-from-npm\">how to install Highcharts from npm<\/a>.\u00a0Highstock and Highmaps are available in the same package as Highcharts.<\/p>\n<div id=\"highcharts-ybinum\" data-highcharts-chart=\"0\"><\/div>\n<h2>Example with Browserify and Webpack<\/h2>\n<p>One of the popular things to do in a CommonJS environment is the use of bundle systems. <a href=\"http:\/\/browserify.org\/\">Browserify<\/a> and <a href=\"http:\/\/webpack.github.io\/\">Webpack<\/a> are great examples of such systems. Below you can find a simple example of how to use Highcharts with these.<\/p>\n<p>In your application file, do the following to load and use Highcharts<\/p>\n<pre>var Highcharts = require('highcharts'); \/\/ Since 4.2.0\r\nHighcharts.chart('container', { \/*Highcharts options *\/});<\/pre>\n<p>Afterwards you use your bundle system to generate a single distribution file.\u00a0The result will be a nicely packed JavaScript file.<\/p>\n<div id=\"highcharts-ybinum\"><\/div>\n<p><script src=\"https:\/\/cloud.highcharts.com\/inject\/ybinum\" defer=\"defer\" type=\"text\/javascript\"><\/script><\/p>\n<h2>Example with React Application<\/h2>\n<p>Isomorphic JavaScript, also called universal JavaScript, is a term for code that can run both on the client and the server. One of the most popular isomorphic libraries today is <a href=\"http:\/\/facebook.github.io\/react\/\">React<\/a>. Below you can find an example of how to use Highcharts with React.<\/p>\n<p>If a window is not present, Highcharts will not run, unless explicitly told to. This means that Highcharts is not executed on the server side. If you still would like to do so, you will have to pass in a valid window as a parameter.<\/p>\n<p>This is the simplest example of how to use Highcharts with React. For React users it is advisable to integrate Highcharts as a component, which will improve reusability.<\/p>\n<pre>var React = require('react'),\r\n    ReactDOM = require('react-dom'),\r\n    Highcharts = require('highcharts'); \/\/ Since 4.2.0\r\nvar element = React.createElement('div', { id: 'chart' });\r\nReactDOM.render(element, document.getElementById('react-app'), function () {\r\n   \/\/ Load Highcharts with adapter once window is present\r\n   Highcharts.chart('chart', { \/*Highcharts options*\/});\r\n});<\/pre>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Highcharts (from version 4.1.10 and above) is available to load in CommomJS environment like Node.js!<\/p>\n","protected":false},"author":22,"featured_media":8656,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"meta_title":"","meta_description":"","hc_selected_options":[],"footnotes":""},"categories":[211],"tags":[1094,818],"coauthors":[712],"class_list":["post-4824","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","tag-highcharts-core","tag-nodejs"],"_links":{"self":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/4824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/comments?post=4824"}],"version-history":[{"count":1,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/4824\/revisions"}],"predecessor-version":[{"id":29045,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/4824\/revisions\/29045"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media\/8656"}],"wp:attachment":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media?parent=4824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/categories?post=4824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/tags?post=4824"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/coauthors?post=4824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}