This is the Express.js backend API for the Pragament Chrome Extension. It replaces the old Firebase Cloud Functions, serving as the central coordinator for Firestore data persistence and Firebase Cloud Messaging (FCM) push notifications.
- Runtime: Node.js
- Framework: Express.js
- SDK: Firebase Admin SDK
- Environment: dotenv, cors, nodemon (for development)
- Navigate to the backend directory:
cd express_js - Install npm packages:
npm install
To authorize the server to speak to Firestore and send push notifications via FCM, you must supply a Service Account key:
- Open the Firebase Console.
- Select your project
eschool-dev-4c6b4(or relevant project). - Click the Gear Icon ⚙ next to Project Overview, and choose Project Settings.
- Go to the Service Accounts tab.
- Click Generate New Private Key, then click Generate Key to download the JSON credentials file.
- Rename the downloaded file to
serviceAccountKey.json. - Place the file inside the backend config directory:
express_js/config/serviceAccountKey.json
(Note: .gitignore has been pre-configured to ensure this key is never committed to Git).
Configure settings by editing the .env file in the project root:
PORT: HTTP port the server listens on (defaults to3000).GOOGLE_APPLICATION_CREDENTIALS: Path to your service account key file (defaults toconfig/serviceAccountKey.json).FIREBASE_PROJECT_ID: Your Firebase Project ID (defaults toeschool-dev-4c6b4).
- Development Mode (with hot-reload via nodemon):
npm run dev
- Production Mode:
npm start
- Ensure the Express server is running locally at
http://localhost:3000. - The extension is pre-configured to point its
BACKEND_BASEvariable tohttp://localhost:3000inconfig.js. - Open
chrome://extensionsin Google Chrome and click Reload under the Lab Policy Whitelist extension. - Test the workflows:
- Ask Class: Submit a question from a W3Schools editor page. The extension makes a POST request to
http://localhost:3000/api/questions, saving the question and triggering multicast FCM notifications to classmates. - Submit Answer: Solve a question from the Student Dashboard. The dashboard makes a POST request to
http://localhost:3000/api/answers, saving the answer response and triggering an FCM notification to the original asker.
- Ask Class: Submit a question from a W3Schools editor page. The extension makes a POST request to