Skip to main content
This guide walks you through setting up Meilisearch with JavaScript/Node.js.

Prerequisites

1. Install the SDK

npm install meilisearch
# or
yarn add meilisearch

2. Connect to Meilisearch

import { MeiliSearch } from 'meilisearch'

const client = new MeiliSearch({
  host: process.env.MEILISEARCH_URL,
  apiKey: process.env.MEILISEARCH_API_KEY
})
Set your environment variables:
export MEILISEARCH_URL="https://your-instance.meilisearch.io"  # or http://localhost:7700
export MEILISEARCH_API_KEY="your_api_key"
Get a free Cloud instance →

3. Add documents

const movies = [
  { id: 1, title: 'The Matrix', genres: ['Action', 'Sci-Fi'], year: 1999 },
  { id: 2, title: 'Inception', genres: ['Action', 'Thriller'], year: 2010 },
  { id: 3, title: 'Interstellar', genres: ['Drama', 'Sci-Fi'], year: 2014 }
]

// Add documents to the 'movies' index
const task = await client.index('movies').addDocuments(movies)

// Wait for indexing to complete
await client.waitForTask(task.taskUid)
const results = await client.index('movies').search('matrix')

console.log(results.hits)
// [{ id: 1, title: 'The Matrix', genres: ['Action', 'Sci-Fi'], year: 1999 }]

5. Search with filters

First, configure filterable attributes:
await client.index('movies').updateFilterableAttributes(['genres', 'year'])
Then search with filters:
const results = await client.index('movies').search('', {
  filter: 'genres = "Sci-Fi" AND year > 2000'
})

Full example

import { MeiliSearch } from 'meilisearch'

const client = new MeiliSearch({
  host: process.env.MEILISEARCH_URL,
  apiKey: process.env.MEILISEARCH_API_KEY
})

async function main() {
  // Add documents
  const movies = [
    { id: 1, title: 'The Matrix', genres: ['Action', 'Sci-Fi'], year: 1999 },
    { id: 2, title: 'Inception', genres: ['Action', 'Thriller'], year: 2010 },
    { id: 3, title: 'Interstellar', genres: ['Drama', 'Sci-Fi'], year: 2014 }
  ]

  const task = await client.index('movies').addDocuments(movies)
  await client.waitForTask(task.taskUid)

  // Search
  const results = await client.index('movies').search('inter')
  console.log(results.hits)
}

main()

Next steps

Front-end integration

Add search to your React, Vue, or Angular app

Full-text search

Configure ranking and relevancy

Filtering

Add filters and facets

API reference

Explore all search parameters

Resources