Firebase Setup Guide
Welcome to FirestorePilot
Your personal assistant for setting up Firebase and Firestore. Follow the steps below to get your project up and running quickly and securely.
The first step is to create a new project in the Firebase Console. This will be the central hub for managing your application's backend services.
- Navigate to the Firebase Console.
- Click on "Add project".
- Enter a name for your project, for example, "hamdi-translators". Firebase will generate a unique project ID.
- You can choose to enable Google Analytics. For this guide, it's optional.
- Click "Create project". Firebase will provision your project, which may take a few moments.
Once your project is created, you need to enable Firestore. This is the NoSQL database where your application data will be stored.
- From your project's dashboard, navigate to "Build" > "Firestore Database" in the left-hand menu.
- Click on "Create database".
- You'll be prompted to choose between Production mode and Test mode for your security rules. Select Production mode for better security.
- Select a location for your Firestore data. It's recommended to choose a location close to your users. `us-central` is a good default.
- Click "Enable".
A service account allows your Node.js server to authenticate with Firebase services securely. This is required for the Firebase Admin SDK.
- In the Firebase Console, click the gear icon next to "Project Overview" and select "Project settings".
- Go to the "Service accounts" tab.
- Click "Generate new private key". A confirmation dialog will appear.
- Click "Generate key". This will download a JSON file with your credentials.
- Rename this file to `firebase-service-account.json` and place it in the root of your Node.js project.
Firestore requires composite indexes for complex queries. Describe your data access patterns below, and our AI will suggest the necessary indexes to optimize performance.
Security rules are crucial for protecting your data. For initial development, you can use temporarily permissive rules. Enter your project name to generate them.
Your `firebase-service-account.json` file is highly sensitive. Get best-practice suggestions for storing and handling it securely in different environments.
After setting up your credentials, it's essential to verify that your application can connect to Firebase. You can do this with a simple test script.
Node.js Test Script
Create a test file (e.g., `test-firebase.js`) in your project root and run it with `node test-firebase.js`.
import { initializeApp, cert } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
// IMPORTANT: Path to your service account key file
const serviceAccount = require('./firebase-service-account.json');
initializeApp({
credential: cert(serviceAccount)
});
const db = getFirestore();
async function verifyConnection() {
try {
const snapshot = await db.collection('test-collection').get();
console.log('Firebase connection successful! Found', snapshot.size, 'documents in test-collection.');
// You can perform a simple write operation too
// await db.collection('test-collection').add({ timestamp: new Date() });
// console.log('Successfully wrote to test-collection.');
} catch (error) {
console.error('Firebase connection failed:', error);
}
}
verifyConnection();