Skip to content

Latest commit

 

History

History
129 lines (90 loc) · 3.28 KB

README.md

File metadata and controls

129 lines (90 loc) · 3.28 KB

Medusa v2 Example: Algolia Integration

This directory holds the code for the Algolia Integration Tutorial.

You can either:

Prerequisites

Installation

  1. Clone the repository and change to the algolia-integration directory:
git clone https://github.com/medusajs/examples.git
cd examples/algolia-integration

2. Rename the .env.template file to .env.

3. If necessary, change the PostgreSQL username, password, and host in the DATABASE_URL environment variable.

4. Set the Algolia environment variables:

ALGOLIA_APP_ID=
ALGOLIA_API_KEY=
ALGOLIA_PRODUCT_INDEX_NAME=

Where:

  • ALGOLIA_APP_ID is the ID of an Algolia application.
  • ALGOLIA_API_KEY is the Algolia Admin API key.
  • ALGOLIA_PRODUCT_INDEX_NAME is the name of the index in Algolia.

Learn more about retrieving these variables in the tutorial

5. Install dependencies:

yarn # or npm install

6. Setup and seed the database:

npx medusa db:setup
yarn seed # or npm run seed

7. Start the Medusa application:

yarn dev # or npm run dev

You'll find an "Algolia" page in the Medusa Admin's Settings sidebar.

Copy into Existing Medusa Application

If you have an existing Medusa application, copy the following directories and files into your project:

  • src/admin
  • src/api
  • src/modules/algolia
  • src/subscribers
  • src/workflows

Then, add the Algolia Module to medusa-config.ts:

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "./src/modules/algolia",
      options: {
        appId: process.env.ALGOLIA_APP_ID!,
        apiKey: process.env.ALGOLIA_API_KEY!,
        productIndexName: process.env.ALGOLIA_PRODUCT_INDEX_NAME!,
      }
    }
  ],
})

Next, add the following environment variables:

ALGOLIA_APP_ID=
ALGOLIA_API_KEY=
ALGOLIA_PRODUCT_INDEX_NAME=

Where:

  • ALGOLIA_APP_ID is the ID of an Algolia application.
  • ALGOLIA_API_KEY is the Algolia Admin API key.
  • ALGOLIA_PRODUCT_INDEX_NAME is the name of the index in Algolia.

Learn more about retrieving these variables in the tutorial

After that, install the algoliasearch library:

yarn add algoliasearch # or npm install algoliasearch

This guide was implemented with algoliasearch@^5.21.0.

Finally, run migrations:

npx medusa db:migrate

More Resources