Install the JavaScript API Client
You are currently reading the JavaScript API Client v4 documentation. Read our migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
npm
npm is the recommended installation method when building large scale applications with the Algolia JavaScript API Client. It pairs nicely with module bundlers such as Webpack or Rollup.
1
npm install algoliasearch
CDN Links
For prototyping or learning purposes, algoliasearch
is also available over CDN.
1
2
3
4
5
<!-- for the search only version -->
<script src="https://cdn.jsdelivr.net/npm/algoliasearch@4.5.1/dist/algoliasearch-lite.umd.js"></script>
<!-- for the default version -->
<script src="https://cdn.jsdelivr.net/npm/algoliasearch@4.5.1/dist/algoliasearch.umd.js"></script>
If you are using native ES Modules, there is also builds compatible with ES Modules:
1
2
3
4
5
6
7
<script type="module">
// for the search only version
import algoliasearch from 'https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.esm.browser.js';
// for the default version
import algoliasearch from 'https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch.esm.browser.js';
</script>
jsDelivr is a third-party CDN. We are not able to provide support regarding third party services.
Compatibility Note
algoliasearch supports all popular browsers, including Internet
Explorer 11 and above, although some polyfills are required for
older browsers: Promise
, Object.entries
,
and Object.assign
.
1
<script src="https://polyfill.io/v3/polyfill.min.js?features=Promise%2CObject.entries%2CObject.assign"></script>
Polyfill.io is a third-party CDN. We are not able to provide support regarding third party services.
algoliasearch supports Node.js 8.x and above.
Explanation of Different Builds
In the dist
directory of the NPM package you will find
different builds of algoliasearch. Here’s an overview of the difference
between them:
-
algoliasearch-lite
search only version of the api client, optimized for size and search:- algoliasearch-lite.umd.js
- algoliasearch-lite.esm.browser.js
-
algoliasearch
: default version of the api client, ready to work with all algolia features such as search, analytics, insights, and others:- algoliasearch.cjs.js
- algoliasearch.umd.js
- algoliasearch.esm.browser.js
Language-specific notes
The JavaScript client works both on the frontend (browsers) or on the backend (Node.js) with the same API.
The backend (Node.js) API can be used to index your data using your Algolia admin API keys.
Our JavaScript library is UMD compatible, you can use it with any module loader.
When not using any module loader, it will export an algoliasearch
function in the window
object.
Our JavaScript snippets use the ES6 syntax. While most modern browsers natively support ES6, make sure you adapt your code so it properly works your end users’ environment. To transpile ES6 code into ES5, we recommend using Babel. We also expose scoped packages such as @algolia/client-search
in ES6, meaning you have to transform them as well.