1.1.5 • Published 6 months ago

@nodeboot/starter-firebase v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@nodeboot/starter-firebase Documentation

Overview

@nodeboot/starter-firebase seamlessly integrates Firebase services into your Node.js application using the Node-Boot framework. Drawing inspiration from Spring Boot's auto-configuration, this package simplifies Firebase setup by:

  • Auto-configuring Firebase Services: Automatically initializes Firebase services based on your configuration.
  • Dependency Injection (DI) Support: Provides ready-to-use Firebase service instances as beans in the DI container.
  • Centralized Configuration: Reads settings from an app-config.yaml file, promoting an opinionated and consistent configuration approach.

Installation

Install the package via npm:

npm install @nodeboot/starter-firebase

Configuration

To enable Firebase integration, add your Firebase settings to the app-config.yaml file under the integrations.firebase path.

Example app-config.yaml:

integrations:
    firebase:
        serviceAccount: "./path/to/firebase.service-account.json"
        realtimeDatabaseUrl: "https://<your-database-name>.firebaseio.com"
        storageBucket: "<your-storage-bucket>.appspot.com"
        projectId: "<your-project-id>"

Configuration Properties:

  • serviceAccount (string): Path to your Firebase service account JSON file. Learn more.
  • realtimeDatabaseUrl (string): URL of your Firebase Realtime Database. Learn more.
  • storageBucket (string): Name of your Google Cloud Storage bucket (without gs:// prefix). Learn more.
  • projectId (string): ID of your Google Cloud project. Learn more.

Enabling Firebase Integration

In your main application class, apply the @EnableFirebase decorator to activate Firebase auto-configuration:

import {EnableFirebase} from "@nodeboot/starter-firebase";
import {NodeBootApplication, NodeBootApp} from "@nodeboot/core";
import {EnableDI, EnableComponentScan} from "@nodeboot/core";
import {ExpressServer} from "@nodeboot/express";
import {Container} from "typedi";

@EnableDI(Container)
@EnableFirebase()
@EnableComponentScan()
@NodeBootApplication()
export class MyApp implements NodeBootApp {
    start(): Promise<void> {
        return NodeBoot.run(ExpressServer);
    }
}

Accessing Firebase Services

With auto-configuration enabled, you can inject Firebase services into your components using the DI container.

Example Service:

import {Service} from "@nodeboot/core";
import {FIREBASE_MACHINE_LEARNING_BEAN} from "@nodeboot/starter-firebase";
import {Inject} from "typedi";
import {Logger} from "winston";
import {remoteConfig} from "firebase-admin";

@Service()
export class FirebaseService {
    constructor(
        private readonly logger: Logger,
        @Inject(FIREBASE_MACHINE_LEARNING_BEAN)
        private readonly firebaseRemoteConfig: remoteConfig.RemoteConfig,
    ) {}

    public async fetchRemoteConfigVersions() {
        this.logger.info("Fetching Firebase Remote Config versions...");

        try {
            const result = await this.firebaseRemoteConfig.listVersions();
            this.logger.info(`Retrieved ${result.versions.length} versions.`);
        } catch (error) {
            this.logger.error("Error fetching Remote Config versions:", error);
        }
    }
}

Available Firebase Beans:

Logging

The package utilizes a logger to provide informative messages during the initialization and injection of Firebase services.

If the serviceAccount path is not provided or incorrect, the initialization will log an error:

No configuration provided for Firebase integration. Please configure "integrations.firebase.serviceAccount=./path/to/firebase.service-account.json"

Ensure that your app-config.yaml is correctly set up and the service account file is accessible.

Conclusion

@nodeboot/starter-firebase streamlines the integration of Firebase services into your Node.js application by leveraging Node-Boot's auto-configuration and DI capabilities. With minimal setup, you can access and utilize Firebase services efficiently.

For more detailed information on each Firebase service, refer to the official Firebase Documentation.

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

7 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago