Add Firebase to your Web

Hi, I am pragadeesh, Today let’s just get started to code in FIREBASE, which is an awesome database. Let’s get into it.

Before creating a web app, let’s create a project in firebase console.

  1. Go to Firebase console and create a project,  Here i have created a project with a name “sample”add_project
  2. you will be then redirected to the project Dashboard.dashboar
  3. You can use firebase for building Android, iOS and web applications, for now let’s begin with web app, In future i will show you how to convert this web app to android and iOS using cordova.
  4. Now let’s get the firebase web SDK . Just click the option “Add firebase to web app”, a dialog box appears with SDK credentials which you will be using to configure with your web app.firebase_web-sdk
  5. copy the script and add it in your Web app Script , Now you have integrated the firebase SDK to your web app and you’re ready to go. It’s simple right.
  6. Here’s the sample code

<!DOCTYPE html>
<html>
<head>
<meta name=”format-detection” content=”telephone=no”>
<meta name=”msapplication-tap-highlight” content=”no”>
<meta name=”viewport” content=”user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width”>
<title>Sample</title>
</head>
<body>

</body>
</html>

Add this to your script src tag “https://www.gstatic.com/firebasejs/4.3.1/firebase.js”

Create a script and add the below credentials

// Use your config instead of this one
var config = {
apiKey: “AIzaSyCuXlfTMDrC3rXdPb442CkMEwNhYqYHu-U”,
authDomain: “sample-c7c91.firebaseapp.com”,
databaseURL: “https://sample-c7c91.firebaseio.com&#8221;,
projectId: “sample-c7c91”,
storageBucket: “sample-c7c91.appspot.com”,
messagingSenderId: “219135436098”
};
firebase.initializeApp(config);

Note :  In firebase SDK you will be adding a external file like https://www.gstatic.com/firebasejs/4.3.1/firebase.js ,  this is their SDK which will include all features like authentication, database and messaging etc.

To use a feature individually in your web app then you can use just their particular SDK for example

  1. Firebase App – https://www.gstatic.com/firebasejs/4.3.0/firebase-app.js
  2. Firebase Authentication  – https://www.gstatic.com/firebasejs/4.3.0/firebase-auth.js
  3. Firebase Database – https://www.gstatic.com/firebasejs/4.3.0/firebase-database.js
  4. Firebase Messaging – https://www.gstatic.com/firebasejs/4.3.0/firebase-messaging.js

To use all this SDK to one, then you can use https://www.gstatic.com/firebasejs/4.3.1/firebase.js

Now your file should look like this.

code_firebase_add

In next post, let’s see how to write  in database.

Leave a comment

Create a free website or blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started