Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/olegkorol/firebase-cloud-functions-typescript

Boilerplate code with multiple Firebase Cloud Functions in one repository
https://github.com/olegkorol/firebase-cloud-functions-typescript

cloud-function-for-firebase firebase firebase-admin-sdk typescript

Last synced: 3 days ago
JSON representation

Boilerplate code with multiple Firebase Cloud Functions in one repository

Awesome Lists containing this project

README

        

# firebase-cloud-functions-typescript

## Firebase Cloud Functions (TypeScript)

### Quick start

> Requirement: Node.js >= v.8

```bash
# To quickly deploy (or update existing) Firebase Functions to GCP:
$ cd firebase-functions
$ npm install
# set your default project name in the firebase.json file, and then run:
$ npm run deploy

# In order to deploy single functions, you will have to install `firebase-tools` locally:
$ npm install -g firebase-tools
$ firebase deploy --only functions:{functionName}
# The function names can be found in firebase-functions/src/index.ts, e.g. "firebase_firebaseFunction1"
```

The "deploy" command will run tslint, transpile into JavaScript (ES2017) under the "lib" directory, perform unit tests and deploy the transpiled code to Google Cloud Platform.

**Important note: All functions using the "firebase-admin" SDK should initialize the SDK in the following manner:**

```javascript
import * as functions from 'firebase-functions';
import * as admin from "firebase-admin";
try {admin.initializeApp(functions.config().firebase);} catch(e) {}
```

Otherwise, the SDK might be initialized more than once - which will lead to an error on deployment.

### Unit Testing

The Firebase Cloud Functions use unit tests using Mocha and Chai for assertions.

### Creating new functions

Create a `.ts` file under `firebase-functions/src/`.

After that export the function in the `index.ts` file.

If you want to create any unit tests, do so in the `test` folder.