Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/olegkorol/firebase-cloud-functions-typescript
- Owner: olegkorol
- Created: 2018-10-31T19:49:13.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T06:16:27.000Z (almost 2 years ago)
- Last Synced: 2023-06-15T18:11:24.982Z (over 1 year ago)
- Topics: cloud-function-for-firebase, firebase, firebase-admin-sdk, typescript
- Language: TypeScript
- Homepage:
- Size: 923 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
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.