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

0.1.0 • Public • Published

nestjs-ws

NPM version

A ws client service for NestJS.

Installation

$ npm install nestjs-ws --save

Getting Started

To use the WsService, first import WsModule.

import { Module } from '@nestjs/common';
import { WsModule } from 'nestjs-ws';
 
@Module({
  imports: [
    WsModule.register({ url: 'ws://www.host.com/path' }),
  ],
})
export class AppModule {}

Next, inject WsService using normal constructor injection.

import { Injectable } from '@nestjs/common';
import { WsService } from 'nestjs-ws';
 
@Injectable()
export class TestService {
  constructor(private readonly wsService: WsService) {}
 
  async root(): Promise<boolean> {
    const ws = await this.wsService.getClient();
    return true;
  }
}

Configuration

Single Client

@Module({
  imports: [
    WsModule.register({ url: 'ws://www.host.com/path' }),
  ],
})

Multi Clients

@Module({
  imports: [
    WsModule.register([
      { name: 'ws1', url: 'ws://www.host1.com/path' },
      { name: 'ws2', url: 'ws://www.host2.com/path' },
    ]),
  ],
})

Async configuration

@Module({
  imports: [
    WsModule.registerAsync({
      useFactory: (configService: ConfigService) => configService.get('ws'),
      inject:[ConfigService]
    }),
  ],
})

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i nestjs-ws

Weekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

414 kB

Total Files

29

Last publish

Collaborators

  • chunkai1312