Skip to content
πŸ”Ž Algolia Search API Client for JavaScript platforms
Branch: develop
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create Nov 14, 2016
dist 3.32.1 Mar 14, 2019
examples chore(parse): remove parse build and examples (#705) Jun 14, 2018
plugins chore: pass eslint and jsfmt on whole code Jul 9, 2015
scripts chore(parse): remove parse build and examples (#705) Jun 14, 2018
src fix(ua): add space between added agent (#751) Apr 11, 2019
test fix(ua): add space between added agent (#751) Apr 11, 2019
.gitattributes chore(parse): remove parse build and examples (#705) Jun 14, 2018
.gitignore chore: change the way we handle deps Sep 16, 2015
.travis.yml test(ci): use version from nvm (#745) Mar 14, 2019 3.32.1 Mar 14, 2019 test(unit): fix and reactivate unit tests in PRs (#701) Jun 4, 2018
LICENSE.txt Initial version of Algolia Search Javascript client May 21, 2013 docs(readme): clarify which API key to use (#723) Oct 1, 2018
index.js spelling (#736) Mar 14, 2019
lite.js fix(nodejs): allow universal lite applications Jun 16, 2016
package.json 3.32.1 Mar 14, 2019
reactnative.js updates doc and add alias for react native build Nov 4, 2015
yarn.lock test(unit): fix and reactivate unit tests in PRs (#701) Jun 4, 2018
zuul.config.js test(unit): fix and reactivate unit tests in PRs (#701) Jun 4, 2018

Algolia Search API Client for JavaScript

Algolia Search is a hosted full-text, numerical, and faceted search engine capable of delivering realtime results from the first keystroke. The Algolia Search API Client for JavaScript lets you easily use the Algolia Search REST API from your JavaScript code.

Version Build Status License Downloads jsDelivr Hits

Browser tests

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.

API Documentation

You can find the full reference on Algolia's website.

Table of Contents

  1. Install

  2. Quick Start

  3. Getting Help

Getting Started



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

Node.js / React Native / Browserify / webpack

We are browserifyable and webpack friendly.

npm install algoliasearch --save

TypeScript typings

For Typescript typings, we provide the definition file via typings

npm install --save @types/algoliasearch


tns plugin add nativescript-algolia


bower install algoliasearch -S

<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:

<script src=""></script>
Other CDNS

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

Search only/lite client

We have a lightweight build available that can only do searches. Use it when filesize is important to you or if you like to include only what you need.

Find it on jsDelivr:

<script src=""></script>

Quick Start

In 30 seconds, this quick start tutorial will show you how to index and search objects.

Initialize the client

You first need to initialize the client. For that you need your Application ID and API Key. You can find both of them on your Algolia account.

// var algoliasearch = require('algoliasearch');
// var algoliasearch = require('algoliasearch/reactnative');
// var algoliasearch = require('algoliasearch/lite');
// or just use algoliasearch if you are using a <script> tag
// if you are using AMD module loader, algoliasearch will not be defined in window,
// but in the AMD modules of the page

var client = algoliasearch('applicationID', 'apiKey');

Push data

Without any prior configuration, you can start indexing 500 contacts in the contacts index using the following code:

for this use: admin API key in client instantiation

var index = client.initIndex('contacts');
var contactsJSON = require('./contacts.json');

index.addObjects(contactsJSON, function(err, content) {
  if (err) {


You can now search for contacts using firstname, lastname, company, etc. (even with typos):

for this use: search only API key in client instantiation

// firstname'jimmie', function(err, content) {

// firstname with typo'jimie', function(err, content) {

// a company'california paint', function(err, content) {

// a firstname & company'jimmie paint', function(err, content) {


Settings can be customized to tune the search behavior. For example, you can add a custom sort by number of followers to the already great built-in relevance:

for this use: admin API key in client instantiation

  'customRanking': ['desc(followers)']
}, function(err, content) {

You can also configure the list of attributes you want to index by order of importance (first = most important):

Note: Since the engine is designed to suggest results as you type, you'll generally search by prefix. In this case the order of attributes is very important to decide which hit is the best:

  'searchableAttributes': [
}, function(err, content) {

Client options

In most situations, there is no need to tune the options. We provide this list to be transparent with our users.

  • timeout (Number) timeout for requests to our servers, in milliseconds
    • in Node.js this is an inactivity timeout. Defaults to 15s
    • in the browser, this is a global timeout. Defaults to 2s (incremental)
  • protocol (String) protocol to use when communicating with algolia
    • in the browser, we use the page protocol by default
    • in Node.js it's https by default
    • possible values: 'http:', 'https:'
  • ([String]) array of read hosts to use to call Algolia servers, computed automatically
  • hosts.write ([String]) array of write hosts to use to call Algolia servers, computed automatically
  • httpAgent (HttpAgent) node-only Node.js httpAgent instance to use when communicating with Algolia servers.
  • dsn ([Boolean=true]) enable or disable DSN (defaults to true). Disable this when you're in a backend situation, but still have worldwide DSN for another (frontend) search.

To pass an option, use:

var client = algoliasearch(applicationId, apiKey, {
  timeout: 4000

Callback convention

Every API call takes a callback as last parameter. This callback will then be called with two arguments:

  1. error: null or an Error object. More info on the error can be find in error.message.
  2. content: the object containing the answer from the server, it's a JavaScript object


If you do not provide a callback, you will get a promise (but never both).

Promises are the native Promise implementation.

We use jakearchibald/es6-promise as a polyfill when needed.

Request strategy

The request strategy used by the JavaScript client includes:

Connections are always keep-alive.


Browser only

To avoid performing the same API calls twice search results will be stored in a cache that will be tied to your JavaScript client and index objects. Whenever a call for a specific query (and filters) is made, we store the results in a local cache. If you ever call the exact same query again, we read the results from the cache instead of doing an API call.

This is particularly useful when your users are deleting characters from their current query, to avoid useless API calls. Because it is stored as a simple JavaScript object in memory, the cache is automatically reset whenever you reload the page.

It is never automatically purged, nor can it be completely disabled. Instead, we provide the index.clearCache() (or client.clearCache() if you're using the Search multiple indices method that you can call to reset it.

Proxy support

Node.js only

If you are behind a proxy, just set HTTP_PROXY or HTTPS_PROXY environment variables before starting your Node.js program.

HTTP_PROXY= node main.js


Node.js only

Keep-alive is activated by default.

Because of the nature of keepalive connections, your process will hang even if you do not do any more command using the client.

To fix this, we expose a client.destroy() method that will terminate all remaining alive connections.

You should call this method when you are finished working with the AlgoliaSearch API. So that your process will exit gently.

Note: keep-alive is still always activated in browsers, this is a native behavior of browsers.


The client will send you errors when a method call fails for some reasons.

You can get detailed debugging information:'something', function searchDone(err) {
  if (err) {

err.debugData contains the array of requests parameters that were used to issue requests.

Getting Help

You can’t perform that action at this time.