-
Improved cold start performance - Cold start/boot time is one of the biggest issues many developers and companies come across when using cloud functions. This boilerplate uses the best practices to reduce the cold start time thus improving performance.
-
Multiple environments (local, dev, prod) - A simple convetion enables the same code to run on multiple environments.
-
Testability - The recomended architecture enables simple unit tests with minimum external dependencies.
-
Straight foward deployment - Running the code locally, or deploying to multiple environments should be simple. You run one command and your code is deployed in seconds.
- Uses
dev service-account
and atest schema
- The test schema is injected
- use custom node script to run the tests
This project supports two environments.
One is meant to be a development environment, dev
and the other should be a production environment, prod
.
./firebaserc
defines alias for their firebase project id's./functions/service-account/
should have the respectivesservice-account
filesdev-service-account.json
for dev environmentprod-service-account.json
for prod environment
build
runs theTypescript
compilerserve
runsbuild
and thefirebase
cli with emulatorslocal
runs ashell
script that makes sure we're usingdev
credentialsdeploy:staging
runs ashell
script that makes sure we're usingdev
credentialsdeploy:prod
runs ashell
script that makes sure we're usingprod
credentials
Cold start (Cold boot) time has been one of the biggest issues many developers and companies come across when using cloud functions. This boilerplate uses the best practices to reduce the cold start time thus improving performance.
By taking advantage of TypeScripts dynamic 'async' import, this ensures unused code and imports and not loaded unncessarily during start time but only when the specific function is invoked.
Using only one file, index.js
, for everything doesn't work for a serious app. It becomes hard to scan through, hard to easily follow up with the code. This scaffold recognizes that and aims to solve that.
There have been a lot of ways suggested to split cloud functions properly, Firebase also has suggestions, but it doesn't take into account the effect on the cold start time.
Every Firebase HTTP function makes use of express.js
underneath. Explicitly using it in structuring your endpoints has proved to more beneficial, both in structure and maximization of resources.
- All your HTTP requests are now accessed through one Cloud Function. This helps with the "Number of functions" limit (which is 1,000), meaning no matter the number of endpoints you have, they would all count as one function.
- Improves cold start time - Due to the way cloud functions are invoked, having all endpoints accessible through one function enables instances to be reused.