Firebase Setup
This blog explains how to setup a Firebase project and deploy a sample Firebase Hosting application.
Create a Firebase project
Follow the steps mentioned in https://firebase.google.com/docs/web/setup
Go to Firebase Console.
Click Add project and provide details
Enter project name
Firebase will generate a unique project id by adding a suffix.
Select Country
Once project creation is successful, click Continue. This will take you to project console.
Click “Add Firebase to your Web App” link to copy initialization code snippet.
The snippet contains initialization information to configure the Firebase JavaScript SDK to use Authentication, Cloud Storage, the Realtime Database, and Cloud Firestore.
Sample snippet from documentation.
Include the above snippet and the firebase libraries(.js files) to index.html of your project.
Install Firebase CLI
Install Node.js
This is a prerequisite to install firebase CLI. I have installed the latest version (10.5.0) using package manager. Refer https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
Above command will download the shell script available at https://deb.nodesource.com/setup_10.x And execute it as root user. The script will run “sudo apt-get update” and show commands to install Node.js
I got below error as curl is not available.
Install curl
$ sudo apt install curl
Also tried below command but got same error.
sudo apt-get install curl python-software-properties
Download the script using wget
Install script
$ sudo bash setup_10.x
sudo bash setup_10.x
|
Run `sudo apt-get install -y nodejs` to install Node.js 10.x and npm
Install nodejs
$sudo apt-get install -y nodejs
Install dev tools to build native addons
$ sudo apt-get install gcc g++ make
Install yarn package manager
To install the Yarn package manager, run:
$ wget https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ sudo apt-key add pubkey.gpg
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn
Verify installation
Verify installation is successful for:
- Node
- npm package manager
- yarn package manager
Run hello world using Node
$ node
> console.log('Hello World')
Sample output:
Install Firebase CLI
Install firebase cli using npm
$ sudo npm install -g firebase-tools
Login to google account from firease cli
$ firebase login
This will open up a new tab in browser and ask to login to google account. Login to your google account and allow firebase cli to access necessary information. Now it will show login successful message.
Run firebase list to view the project created from firebase console
$ firebase list
Download starter project
Create new project
Firebase init
I have selected all modules. So after running ‘firebase init’ below files/folders were created in the current dir.
This will create below files in the current dir.
database.rules.json
firebase.json
firestore.indexes.json
firestore.rules
functions
package-lock.json
public
storage.rules
Deploy new project
‘firebase deploy’
But deploy failed with below error:
Error: HTTP Error: 400, Project 'don-project-36b6f' is not a Cloud Firestore enabled project.
Enable Cloud Firestore from Firebase Console
Go to Firebase Console
Select Database from left side navigation
Click Get started.
The popup will show two options
Select “Start in locked mode’
Click “Enable”
Try firebase deploy again
Once the operation completed, try ‘firebase deploy’ again
firebase deploy
Click hosting url
As shown above, the sample app got deployed successfully.
No comments:
Post a Comment