Skip to content

JavaScript Client

Flapjack works with the official algoliasearch JavaScript client. You just change the host configuration.

Terminal window
npm install algoliasearch
import { liteClient as algoliasearch } from 'algoliasearch/lite';
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', {
hosts: [{ url: 'localhost:7700', protocol: 'http' }],
});

For Flapjack Cloud:

const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', {
hosts: [{ url: 'YOUR_IP:7700', protocol: 'https' }],
});
const results = await client.search({
requests: [
{
indexName: 'movies',
query: 'matrix',
hitsPerPage: 10,
},
],
});
console.log(results.results[0].hits);
import algoliasearch from 'algoliasearch';
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', {
hosts: [{ url: 'localhost:7700', protocol: 'http' }],
});
// Add objects
await client.saveObjects({
indexName: 'movies',
objects: [
{ objectID: '1', title: 'The Matrix', year: 1999 },
{ objectID: '2', title: 'Inception', year: 2010 },
],
});
await client.batch({
indexName: 'movies',
batchWriteParams: {
requests: [
{ action: 'addObject', body: { objectID: '1', title: 'The Matrix' } },
{ action: 'deleteObject', body: { objectID: '99' } },
],
},
});
const results = await client.search({
requests: [
{
indexName: 'movies',
query: 'action',
filters: 'year > 2000',
facets: ['genre'],
},
],
});
const movie = await client.getObject({
indexName: 'movies',
objectID: '1',
});
await client.deleteObject({
indexName: 'movies',
objectID: '1',
});

The algoliasearch package includes full TypeScript types. No additional @types package needed.

import { liteClient as algoliasearch } from 'algoliasearch/lite';
import type { SearchResponse } from 'algoliasearch';
interface Movie {
objectID: string;
title: string;
year: number;
genre: string;
}
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', {
hosts: [{ url: 'localhost:7700', protocol: 'http' }],
});
const results = await client.search<Movie>({
requests: [{ indexName: 'movies', query: 'matrix' }],
});

The same client works in Node.js:

import algoliasearch from 'algoliasearch';
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', {
hosts: [{ url: 'localhost:7700', protocol: 'http' }],
});
// Full client (search + indexing)
await client.saveObjects({
indexName: 'movies',
objects: [
{ objectID: '1', title: 'The Matrix', year: 1999 },
],
});
const results = await client.search({
requests: [{ indexName: 'movies', query: 'matrix' }],
});