1.0.4 • Published 4 years ago

nestjs-mux v1.0.4

Weekly downloads
34
License
MIT
Repository
github
Last release
4 years ago

nestjs-mux

Mux module that provides standardized setup and dependency injection in a Nest project for the Mux API client.

Installation

Yarn

yarn add nestjs-mux

npm

npm install nestjs-mux --save

Getting Started

Configuration

Import and configure MuxModule with Mux's access and secret tokens into the root module AppModule.

import { Module } from '@nestjs/common';
import { MuxModule } from 'nestjs-mux';

@Module({
  imports: [
    MuxModule.forRoot({
      id: idToken,
      secret: secretToken,
    }),
  ],
})
export default class AppModule {}

Asynchronous

If you need to load the configuration options asynchronously you can use the following options:

Use Factory Function
import { Module } from '@nestjs/common';
import { MuxModule } from 'nestjs-mux';
import { ConfigModule } from './config/config.module';
import { ConfigService } from './config/config.service';

@Module({
  imports: [
    MuxModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        id: configService.getString('MUX_ID_TOKEN'),
        secret: configService.getString('MUX_SECRET_TOKEN'),
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}
Use Class
import { Module } from '@nestjs/common';
import { MuxModule } from 'nestjs-mux';
import { MuxConfigService } from './config/mux.config.service';

@Module({
  imports: [
    MuxModule.forRootAsync({
      useClass: MuxConfigService,
    }),
  ],
})
export class AppModule {}
Use Existing
import { Module } from '@nestjs/common';
import { MuxModule } from 'nestjs-mux';
import { ConfigModule } from './config/config.module';
import { ConfigService } from './config/mux.config.service';

@Module({
  imports: [
    MuxModule.forRootAsync({
      imports: [ConfigModule],
      useExisting: ConfigService,
    }),
  ],
})
export class AppModule {}

Usage

You can then inject the Mux client into constructors with its decorator.

import * as Mux from '@mux/mux-node';
import { Injectable } from '@nestjs/common';
import { InjectMux } from 'nestjs-mux';

@Injectable()
export default class AppService {
  public constructor(@InjectMux() private readonly muxClient: Mux) {}
}
1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago