# next-algolia-server

> Handle Algolia api with NextJS

Latest version **0.2.7** (published 2021-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install next-algolia-server
pnpm add next-algolia-server
yarn add next-algolia-server
bun add next-algolia-server
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.7 |
| Published | 2021-10-14 |
| First published | 2021-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 17 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ender Bonnet |
| Maintainers | enbonnet |
| Keywords | next, nextjs, node, react, reactjs, search, algolia |

## Links

- npm: https://www.npmjs.com/package/next-algolia-server
- Repository: https://github.com/enBonnet/next-algolia-server
- Homepage: https://github.com/enBonnet/next-algolia-server#readme
- Issues: https://github.com/enBonnet/next-algolia-server/issues
- npm.io page: https://npm.io/package/next-algolia-server

## Dependencies (1)

- [algoliasearch](https://npm.io/package/algoliasearch.md) ^4.10.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.7 (latest) — 2021-10-14
- 0.2.6 — 2021-10-03
- 0.2.5 — 2021-08-04
- 0.2.4 — 2021-08-04
- 0.2.3 — 2021-07-23
- 0.2.2 — 2021-07-23
- 0.2.1 — 2021-07-23
- 0.2.0 — 2021-07-23
- 0.1.2 — 2021-07-23
- 0.1.0 — 2021-07-23

## README

# next-algolia-server

## Install

```bash
yarn add algoliasearch next-algolia-server
```

## Usage

Basic configuration

```js
import AlgoliaServer from "next-algolia-server";

// Create your instance with your algoliaId and algoliaKey
// Get yours https://www.algolia.com/
const algolia = AlgoliaServer.getInstance({ algoliaId, algoliaKey });

// Set your index
algolia.setIndex("blog");

// Set your searchableAttributes
// Read more about this https://www.algolia.com/doc/api-reference/api-parameters/searchableAttributes/
algolia.setSearchableAttributes([
  "title,description",
  "content",
  "categories.name",
]);
```

Then you would be able to use this `algolia` instance to handle your records.

```js
// I did it inside my `getStaticProps`
export async function getStaticProps() {
  // ... functions to get my posts...
  const posts = [];
  // Read more about this https://www.algolia.com/doc/api-reference/api-methods/save-objects/
  // Every record most have a unique `objectID` param
  // Or let algolia generate it with algoliaServer.saveRecords(posts, { autoGenerateObjectIDIfNotExist: true })
  // Be careful if you let algolia generate it you could duplicate your records
  algoliaServer.saveRecords(posts);

  return posts;
}
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License

[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/next-algolia-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
