Search⌘ K
AI Features

Initializing Firebase

Explore how to initialize Firebase within a React application by importing the Firebase library, configuring it properly, and managing separate environments for development and production. This lesson helps you set up Firebase connections correctly to ensure your app runs smoothly with different data sets for testing and deployment.

We'll cover the following...

Importing Firebase

Let’s import Firebase from the library we installed earlier, and then use it within a new Firebase class to initialize Firebase with the configuration we saw in the previous lesson:

Node.js
import app from 'firebase/app';
const config = {
apiKey: process.env.REACT_APP_API_KEY,
authDomain: process.env.REACT_APP_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_DATABASE_URL,
projectId: process.env.REACT_APP_PROJECT_ID,
storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID,
};
class Firebase {
constructor() {
app.initializeApp(config);
}
}
export default Firebase;

That’s all we really need for a Firebase configuration in our ...