Skip to content

Repository files navigation

nhogs-logo

@nhogs/nestjs-firebase

npm peer dependency version Firebasenpm peer dependency version NestJS)

Firebase module for NestJS.

CIMaintainabilityTest Coverage

Continuous Integration tests with Github Action on Firebase Emulator Suite

Installation

npm

$ npm i --save @nhogs/nestjs-firebase

First you need to have a running firebase project. See Add Firebase to your JavaScript project

⚠️ This module only uses Firebase client API

Module

Add the module in app imports with project settings

@Module({imports: [FirebaseModule.forRoot({apiKey: "API_KEY",authDomain: "PROJECT_ID.firebaseapp.com",projectId: "PROJECT_ID",storageBucket: "PROJECT_ID.appspot.com",// Optional name of the app to initialize. Custom name for the Firebase App. The default value is "[DEFAULT]"// appName: "APP_NAME",}),CatsModule,],})exportclassAppModule{}

Check here for an e2e test with real example on Cat module

This module is a simple wrapper on Firebase API and export 3 services.

  • Cloud Firestore
  • Storage
  • Authentication

Cloud Firestore

Exposes most of Firebase firestore web api in the service.

// Add document exampleit("should addDoc",async()=>{constusers=firestoreService.collection("users").withConverter<User>userConverter;constdoc=(awaitfirestoreService.addDoc)<User>(users,u1);constsnapshot=awaitfirestoreService.getDoc(doc);expect(snapshot.data()).toMatchInlineSnapshot(` User { "age": 1, "firstName": "fn1", "lastName": "ln1", } `);});

See firestore.service.spec.ts for detailed usage.

Storage

Exposes most of Firebase storage web api in the service.

// Upload string and get download url exampleit(`should upload string`,async()=>{constfileName="file.txt";awaitstorageService.uploadString(fileName,"text content","raw",{contentType: "text/plain",}).then((snapshot)=>{expect(snapshot.metadata.contentType).toMatchInlineSnapshot(`"text/plain"`);});constdownloadUrl=awaitstorageService.getDownloadURL(fileName);expect(downloadUrl).toMatchInlineSnapshot(`"http://localhost:9199/v0/b/default-bucket/o/file.txt?alt=media&token=86739ce5-a96e-41ad-b807-e05b12e36516"`);});

See storage.service.spec.ts for detailed usage.

Authentication

See auth.service.spec.ts for detailed usage.

License

MIT license

About

Firebase plugin for NestJs

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages