This is the backend repository for the ACM Officer Database
- Node.js (v18 or higher)
- npm or yarn
- Firebase Admin SDK credentials
- Google Cloud SDK (for deployment)
-
Clone the repository
git clone https://github.com/acmutd/officer-database-backend.git cd officer-database-backend -
Install dependencies
npm install
-
Configure Firebase credentials
Caution
Never commit firebase-creds.json to version control!
- Go to Firebase Console
- Select your project
- Navigate to Project Settings → Service Accounts
- Click Generate New Private Key
- Save the downloaded file as
firebase-creds.jsonin the project root
-
Build the TypeScript code
npm run build
-
Start the development server
Note
The Functions Framework runs one function at a time. Use npm run dev to see an interactive menu, or use specific dev scripts.
Tip
You may want to disable the auth and CORS checkers by removing it from the function you want to run, this way you can open it in your browser and not get blocked
Quick start (interactive menu):
npm run devThis will show a menu where you can select which function to run.
Or run a specific function directly:
npm run dev:getOfficers # GET all officers
npm run dev:getOfficer # GET single officer by ID (query param ?id=...)
npm run dev:createOfficer # POST create new officer
npm run dev:updateOfficer # PATCH update officer (query param ?id=...)
npm run dev:deleteOfficer # DELETE officer (query param ?id=...)All functions run at http://localhost:8080
Example workflow:
- Run
npm run devand select "createOfficer" from menu - Send POST request to
http://localhost:8080with officer data - Stop server (Ctrl+C)
- Run
npm run devand select "getOfficers" from menu - Visit
http://localhost:8080to see all officers
officer-database-backend/
├── src/
│ ├── functions/ # Cloud Functions (CRUD operations)
│ │ ├── createOfficer.ts
│ │ ├── getOfficers.ts
│ │ ├── getOfficer.ts
│ │ ├── updateOfficer.ts
│ │ └── deleteOfficer.ts
│ ├── helpers/ # Validation utilities
│ │ └── validators.ts
│ ├── types/ # TypeScript types and Zod schemas
│ │ └── officer.ts
│ ├── middleware.ts # Request validation middleware
│ ├── firebase.ts # Firebase Admin SDK initialization
│ └── index.ts # Function exports
├── tests/ # Test scripts
│ ├── api-test.js
│ └── validator-test.js
├── dist/ # Compiled JavaScript (generated)
├── firebase-creds.json # Firebase credentials (not in git)
├── package.json
├── tsconfig.json
└── README.md
- Local: Uses Functions Framework to simulate Cloud Functions. Each function runs independently at
http://localhost:8080(usenpm run dev:FUNCTION_NAMEto run a specific function) - Production: Each function is deployed separately with its own URL. All functions are accessible via their individual Cloud Functions endpoints.
- Database: Firestore collection
officer
| Environment | Routing | URL Structure |
|---|---|---|
| Local | One function at a time on port 8080 | http://localhost:8080 (function determined by --target flag) |
| Production | Each function has its own endpoint | https://REGION-PROJECT.cloudfunctions.net/FUNCTION_NAME |
"Cannot find module" errors:
- Run
npm run buildto compile TypeScript
Firebase authentication errors:
- Verify
firebase-creds.jsonexists in project root - Check that the service account has Firestore permissions
Port already in use:
- Change the port in
package.jsondev script or kill the process using port 8080
Type errors:
- Run
npm installto ensure all@types/*packages are installed