> ## Documentation Index
> Fetch the complete documentation index at: https://www.meilisearch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript quick start

> Get started with Meilisearch using the JavaScript SDK in 5 minutes.

This guide walks you through setting up Meilisearch with JavaScript/Node.js.

## Prerequisites

* Node.js 14 or higher
* A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](https://www.meilisearch.com/docs/resources/self_hosting/getting_started/quick_start.md))

## 1. Install the SDK

```bash theme={null}
npm install meilisearch
# or
yarn add meilisearch
```

## 2. Connect to Meilisearch

```javascript theme={null}
import { Meilisearch } from 'meilisearch'

const client = new Meilisearch({
  host: process.env.MEILISEARCH_URL,
  apiKey: process.env.MEILISEARCH_KEY
})
```

> [!NOTE]
>
> **Set your environment variables:**
>
> ```bash theme={null}
> export MEILISEARCH_URL="https://your-instance.meilisearch.io"  # or http://localhost:7700
> export MEILISEARCH_KEY="your_api_key"
> ```
>
> [Get a free Cloud instance →](https://cloud.meilisearch.com)

## 3. Add documents

```javascript theme={null}
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)
```

## 4. Search

```javascript theme={null}
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:

```javascript theme={null}
await client.index('movies').updateFilterableAttributes(['genres', 'year'])
```

Then search with filters:

```javascript theme={null}
const results = await client.index('movies').search('', {
  filter: 'genres = "Sci-Fi" AND year > 2000'
})
```

## Full example

```javascript theme={null}
import { Meilisearch } from 'meilisearch'

const client = new Meilisearch({
  host: process.env.MEILISEARCH_URL,
  apiKey: process.env.MEILISEARCH_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

> [card] [Front-end integration](https://www.meilisearch.com/docs/getting_started/instant_meilisearch/javascript.md)
>
> Add search to your React, Vue, or Angular app

> [card] [Full-text search](https://www.meilisearch.com/docs/capabilities/full_text_search/relevancy/relevancy.md)
>
> Configure ranking and relevancy

> [card] [Filtering](https://www.meilisearch.com/docs/capabilities/filtering_sorting_faceting/getting_started.md)
>
> Add filters and facets

> [card] [API reference](https://www.meilisearch.com/docs/reference/api/search/search-with-post.md)
>
> Explore all search parameters

## Resources

* [meilisearch-js on GitHub](https://github.com/meilisearch/meilisearch-js)
* [SDK documentation](https://github.com/meilisearch/meilisearch-js#readme)
* [instant-meilisearch](https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/instant-meilisearch) - InstantSearch adapter


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.