nestjs-mux
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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) {}
}

Readme

Keywords

Package Sidebar

Install

npm i nestjs-mux

Weekly Downloads

17

Version

1.0.4

License

MIT

Unpacked Size

446 kB

Total Files

23

Last publish

Collaborators

  • igassmann
  • clementzezuka