nestjs-ws
v0.1.0
Published
ws client service for nestjs
Downloads
2
Readme
nestjs-ws
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]
}),
],
})