The backend (Node.js) API can be used to index your data using your Algolia admin API keys.
When not using any module loader, it will export an
algoliasearch function in the
You can find the full reference on Algolia's website.
You can either use a package manager like npm or include a
npm install algoliasearch --save
For Typescript typings, we provide the definition file via typings
npm install --save @types/algoliasearch
tns plugin add nativescript-algolia
bower install algoliasearch -S
To include the latest releases and all upcoming features and patches, use this:
We recommend using jsDelivr, but
algoliasearch is also available at:
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:
In 30 seconds, this quick start tutorial will show you how to index and search objects.
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 pagevar client = ;
Without any prior configuration, you can start indexing 500 contacts in the
contacts index using the following code:
var index = client;var contactsJSON = ;index;
You can now search for contacts using firstname, lastname, company, etc. (even with typos):
// firstnameindex;// firstname with typoindex;// a companyindex;// a firstname & companyindex;
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:
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:
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
protocol(String) protocol to use when communicating with algolia
hosts.read([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.
To pass an option, use:
var client =
Every API call takes a callback as last parameter. This callback will then be called with two arguments:
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.
Connections are always
To avoid performing the same API calls twice search results will be stored
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.
It is never automatically purged, nor can it be completely disabled. Instead, we
client.clearCache() if you're using the
Search multiple indices method that you can call to reset it.
If you are behind a proxy, just set
HTTPS_PROXY environment variables before starting your Node.js program.
HTTP_PROXY=http://someproxy.com:9320 node main.js
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
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:
err.debugData contains the array of requests parameters that were used to issue requests.