Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@curo__/nestjs-algolia

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@curo__/nestjs-algolia

The algolia NestJS module based on the official algolia package

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by66.67%
Maintainers
1
Weekly downloads
 
Created
Source

nestjs-algolia

The algolia NestJS module based on the official algolia package by @fvilers

How to install

npm install @curo__/nestjs-algolia

How to use

Register the module

import { AlgoliaModule } from 'nestjs-algolia';

@Module({
  imports: [
    AlgoliaModule.register({
      applicationId: 'YOUR_APPLICATION_ID',
      apiKey: 'YOUR_API_KEY',
    }),
  ],
})
export class AppModule {}

Inject the service

import { AlgoliaService } from 'nestjs-algolia';

@Injectable()
export class AppService {
  constructor(private readonly algoliaService: AlgoliaService) {}

  addRecordToIndex(
    indexName: string,
    record: any,
  ): Promise<algoliasearch.Task> {
    const index = this.algoliaService.initIndex(indexName);

    return index.addObject(record);
  }
}

Async options

Quite often you might want to asynchronously pass your module options instead of passing them beforehand. In such case, use registerAsync() method, that provides a couple of various ways to deal with async data.

Use factory

AlgoliaModule.registerAsync({
  useFactory: () => ({
    applicationId: 'YOUR_APPLICATION_ID',
    apiKey: 'YOUR_API_KEY',
  }),
});

Obviously, our factory behaves like every other one (might be async and is able to inject dependencies through inject).

AlgoliaModule.registerAsync({
  imports: [ConfigModule],
  useFactory: async (configService: ConfigService) => ({
    applicationId: configService.getString('ALGOLIA_APPLICATION_ID'),
    apiKey: configService.getString('ALGOLIA_API_KEY'),
  }),
  inject: [ConfigService],
}),

Use class

AlgoliaModule.registerAsync({
  useClass: AlgoliaConfigService,
});

Above construction will instantiate AlgoliaConfigService inside AlgoliaModule and will leverage it to create options object.

class AlgoliaConfigService implements AlgoliaOptionsFactory {
  createAlgoliaOptions(): AlgoliaModuleOptions {
    return {
      applicationId: 'YOUR_APPLICATION_ID',
      apiKey: 'YOUR_API_KEY',
    };
  }
}

Use existing

AlgoliaModule.registerAsync({
  imports: [ConfigModule],
  useExisting: ConfigService,
}),

It works the same as useClass with one critical difference - AlgoliaModule will lookup imported modules to reuse already created ConfigService, instead of instantiating it on its own.

Versions

Use the following table to match this module with the NestJS version

@curo__/nestjs-algolianestjs
1.x10.x

Keywords

FAQs

Package last updated on 13 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc