The JavaScript API clients let you interact with Algolia’s APIs from the browser or from your Node.js app.

Install the library

All API clients are part of the algoliasearch package, which you can install with npm.

1
npm install algoliasearch@5

The algoliasearch package includes API clients for the Search API, the Personalization API, the Analytics API, and the A/B testing API. If you only need access to methods from a specific API, you can install API clients separately:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Search API
npm install @algolia/client-search
# Recommend API
npm install @algolia/recommend
# Analytics API
npm install @algolia/client-analytics
# A/B testing API
npm install @algolia/client-abtesting
# Ingestion API
npm install @algolia/ingestion
# Insights API
npm install @algolia/client-insights
# Monitoring
npm install @algolia/monitoring
# Personalization API
npm install @algolia/client-personalization
# Query Suggestions API
npm install @algolia/client-query-suggestions
# Usage API
npm install @algolia/client-usage

Test your installation

To test your installation, try running a short program that adds a record to a test index, searches your index, and prints the results.

  1. If you haven’t already, create an Algolia account.

  2. Copy the following code into a new file helloAlgolia.js. Replace ALGOLIA_APPLICATION_ID and ALGOLIA_API_KEY with values from your account. Make sure to use an API key with addObject and search permissions.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    
    // File: helloAlgolia.mjs
    import { algoliasearch } from "algoliasearch";
    
    const appID = "ALGOLIA_APPLICATION_ID";
    // API key with `addObject` and `editSettings` ACL
    const apiKey = "ALGOLIA_API_KEY";
    const indexName = "test-index";
    
    const client = algoliasearch(appID, apiKey);
    
    const record = {objectID: "object-1", name: "test record"};
    
    // Add record to an index
    const { taskID } = await client.saveObject({
      indexName,
      body: record,
    });
    
    // Wait until indexing is done
    await client.waitForTask({
      indexName,
      taskID,
    });
    
    // Search for "test"
    const { results } = await client.search({
      requests: [
        {
          indexName,
          query: "test",
        },
      ],
    });
    
    console.log(JSON.stringify(results));
    

    In production, don’t include your credentials in your code. Use environment variables instead.

  3. Run: node helloAlgolia.mjs

If the command is successful, you’ll see the API response in JSON format.

Next steps

You can view your new index in the Algolia dashboard.

Did you find this page helpful?
JavaScript API clients v5