Learn how to set up your Firebase project, install the SDK, initialize your app, and write data to the Realtime Database with our easy step-by-step guide.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Firebase Project
Step 2: Install Firebase SDK in Your Project
If you are using npm for a Node.js project, run:
npm install firebase
For a web project using a <script> tag, add:
<script src="https://www.gstatic.com/firebasejs/9.x.x/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.x.x/firebase-database.js"></script>
Step 3: Initialize Firebase in Your Application
Add the following code snippet to initialize Firebase. Replace the placeholder values with your Firebase project's actual configuration details from the Firebase Console:
import { initializeApp } from "firebase/app";
import { getDatabase } from "firebase/database";
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
databaseURL: "YOUR_DATABASE_URL",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER\_ID",
appId: "YOUR_APP_ID",
};
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
Step 4: Write Data to Realtime Database
To write data, use the set() method. Here's an example of writing an object to the database:
import { ref, set } from "firebase/database";
function writeUserData(userId, name, email, imageUrl) {
set(ref(database, 'users/' + userId), {
username: name,
email: email,
profile\_picture: imageUrl
});
}
// Call the function
writeUserData('1', 'John Doe', '[email protected]', 'https://example.com/johndoe/profile.jpg');
Step 5: Enable Realtime Database in Firebase Console
Step 6: Test Your Setup
Run your application and confirm that the data is being written to your Firebase Realtime Database.
Check the Firebase Console under the Realtime Database section to see if the data appears as expected.
Ensure your application can connect to the database, and the data structure is correctly written. Customize the data structure as needed for your specific application.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.