Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tranphuquy19/fcm-nestjs

Firebase Cloud Message module for NestJS
https://github.com/tranphuquy19/fcm-nestjs

firebase nest nestjs nodejs typescript

Last synced: 19 days ago
JSON representation

Firebase Cloud Message module for NestJS

Awesome Lists containing this project

README

        



Nest Logo

NestJS FCM push notifications module



Built with NestJS

_This project forked from [CostianuRazvan/nestjs-fcm](https://github.com/CostianuRazvan/nestjs-fcm)_

### Installation

```bash
npm install --save @doracoder/fcm-nestjs
```

### FcmModule

To user FcmService you must add the module first. **The `FcmModule` has a `@Global()` attribute so you should only import it once**.

```typescript
import { Module } from '@nestjs/common';
import { FcmModule } from '@doracoder/fcm-nestjs';
import * as path from 'path';

@Module({
imports: [
FcmModule.forRoot({
firebaseSpecsPath: path.join(__dirname, '../firebase.spec.json'),
}),
],
controllers: [],
})
export class AppModule {}
```

### `FcmService` use firebase.spec.json file to send notifications using firebase-admin dependency.

```typescript
@Injectable()
export class SampleService {
constructor(private readonly fcmService: FcmService) {}

async sendToDevices() {
await this.fcmService.sendNotification([
'device_token_1',
'device_token_2',
]
payload,
silent,
);
}

async sendToTopic(topic: string) {
await this.fcmService.sendToTopic(
topic,
payload,
silent,
);
}
}
```

## Change Log

See [Changelog](CHANGELOG.md) for more information.

## Contributing

Contributions welcome! See [Contributing](CONTRIBUTING.md).

## Author

**Tran Quy**

## License

Licensed under the MIT License - see the [LICENSE](LICENSE) file for details.