API Reference / API Methods / Install the JavaScript API Client
Feb. 12, 2019

Install the JavaScript API Client

From the back end

Node.js / React Native / Browserify / Webpack

We are Browserifyable and Webpack friendly:

1
npm install --save algoliasearch

TypeScript typings

For TypeScript typings, we provide the definition file via Typings:

1
npm install --save-dev @types/algoliasearch

Bower

1
bower install algoliasearch -S

From the front end

You can either use a package manager like npm or include a script tag.

script tag using CDNs

jsDelivr is a global CDN delivery for JavaScript libraries.

To include the latest releases and all upcoming features and patches, use this:

1
<script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
Other CDNs

We recommend using jsDelivr, but algoliasearch is also available at:

We recommend using jsDelivr only for prototyping, not for production applications. Whenever possible, you should host your assets yourself or use a premium CDN service. jsDelivr is a free service and isn’t operated by Algolia, so we won’t be able to provide support if it fails.

Search-only/lite client

We have a lightweight build available that can only perform searches. Use it when file size is important to you or if you want to include only what you need.

Find it on jsDelivr:

1
<script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearchLite.min.js"></script>

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.

Client options

In most situations, there is no need to tune the options. We provide this list for transparency.

  • timeout (Number): timeout for requests to our servers, in milliseconds
    • in Node.js, this is an inactivity timeout (default: 15000)
    • in the browser, this is a global timeout (default: 2000 incremental)
  • protocol (String): protocol to use when communicating with Algolia (default: https:)
    • this applies to both the browser and Node.js
    • possible values: http:, https:
  • hosts.read ([String]): array of read hosts to use to call Algolia servers, automatically computed
  • hosts.write ([String]): array of write hosts to use to call Algolia servers, automatically computed

Node.js-only parameters:

  • httpAgent: http.Agent instance to use when communicating with Algolia servers

To pass an option, use:

1
2
3
var client = algoliasearch(applicationId, apiKey, {
  timeout: 4000,
});

Proxy support

Node.js only

If you are behind a proxy, use the HTTP_PROXY or HTTPS_PROXY environment variables before starting your Node.js program:

1
HTTP_PROXY=http://someproxy.com:9320 node main.js

Did you find this page helpful?