This is the Firebase backend for the Habits Together app. It uses Firebase Cloud Functions and Firestore for data storage.
- Node.js v18.20.5 (use nvm to manage Node versions)
- Firebase CLI (
npm install -g firebase-tools) - Firebase project credentials (
serviceKey.json)
- Navigate to the functions directory:
cd functions- Install dependencies:
npm install- Create a
.envfile in thefunctionsdirectory:
GOOGLE_APPLICATION_CREDENTIALS="./serviceKey.json"- Place your
serviceKey.jsonin thefunctionsdirectory (obtain this from a team member)
The emulators support data persistence to help maintain consistent test data:
npm run em- Starts emulators and loads previously saved data. When stopped (Ctrl+C), it saves any changes to the data directory.npm run em:fresh- Starts emulators with a clean slate and runs the seeding script to populate with fresh test data. Changes are saved on exit.npm run seed- Manually runs the database seeding script to populate with test data.
Note: The data directory is gitignored to prevent committing test data. New developers should run npm run em:fresh to generate their initial test data.
When making changes to cloud functions, you need to rebuild the TypeScript files for the changes to take effect:
npm run buildThis command should be run after making any changes to function code, as the emulator serves the compiled JavaScript files.
npm run em- Start emulators with data persistencenpm run em:fresh- Start emulators with fresh seeded datanpm run seed- Run the database seeding scriptnpm run build- Build TypeScript filesnpm run deploy- Deploy functions to Firebasenpm run logs- View Firebase function logs
To deploy to production:
- Ensure you're logged in:
firebase login- Select the correct project:
firebase use habits-together- Deploy functions:
npm run deployTo dubug port taken when running the emulator search node.exe and java.exe in task manager and kill those tasks then restart the emulator.