Running Firebase Emulators - Memory-Lane-COS301/miniproject-2023 GitHub Wiki
Introduction
This guide is an ongoing project and will be updated as needed. It can be difficult to create a comprehensive guide that is suitable for all team members, given the varying work environments. If you encounter any issues while following the setup steps, please do not hesitate to reach out to the author for assistance.
Dependencies
- Node 16
- Firebase CLI
- Java (JDK Version 11 or higher)
Installing dependencies
Choose the necessary steps from the following installation instructions, which were applied to a freshly installed version of WSL.
- Install Node and NPM (using nvm)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
nvm install 16
npm install -g npm
- Install yarn
npm install --global yarn
- Install Firebase CLI
npm install -g firebase-tools
- Install Java and add
JAVA_HOME
to PATH
sudo apt install default-jre
sudo apt install default-jdk
Running the app
- Clone the repo
https://github.com/ShashinGounden/miniproject-2023
- Make sure you are on the correct branch
The default branch is the dev
branch. Instead of pulling, which retrieves the
remote branch and automatically merges it with your current branch, rather do a
fetch and switch.
git fetch origin dev
git switch dev
- Install dependencies
cd path/to/project
yarn
- Login to Firebase
Login without whatever Google Account you like.
firebase login
- Run the app stack
Run the following commands in separate terminals:
yarn start:api:dev
yarn start:emulators
yarn start:app:dev
The commands will launch the Firebase emulators in demo mode, without using any live Firebase resources. If the application attempts to interact with a Firebase resource, the local emulators will be employed instead.
We chose to use a local demo project for the following reasons:
- Team members don't need to be added and authenticated on the project portal.
- If something goes wrong during development, it won't affect live Firebase resources.
- Project credentials don't need to be stored in version control.
Various ways the emulators can be used
Listed below will likely become valuable in the upcoming weeks. However, you can safely ignore this section for now.
Exporting emulator state
While the emulators are running, you can export their state before closing to
save data, such as the current state of Firestore, for later use when restarting
the emulators. To do this, run the command yarn export:emulators
in a separate
terminal while the emulators are still running. This will create a .emulators
folder in the project. Remember not to commit this folder; it is already added
to the .gitignore
file for your convenience.
Importing emulator state
If you want to restore the previous state of the emulators you were working on,
run yarn start:emulators:imported
instead of yarn start:emulators
. If you
prefer to start from a clean slate, use yarn start:emulators
.
Seeding the Firestore database
Run the emulators and seed the Firestore database with yarn seed:emulators
.
This adds dummy data to the database, which the app can use.