Add Firebase To Your Vue JS App

Last modified on April 20th, 2022
Raja Tamil

In this Vuejs tutorial, You’re going to learn how to add Firebase to your Vue JS 2 web app in minutes with STEP by STEP instructions.

Create Vue JS Project using Vue CLI

STEP 01: First you need to install Node.js & NPM (Node Package Manager) onto your computer if you haven’t done so already.

Check to see if you have installed node with the following command on the Terminal / Command Prompt:

node -v

STEP 02: Install vue using vue cli globally (-g) which is the easiest way to get started with Vue.

npm install -g vue-cli

STEP 03: Initialize Vue Project via Web Pack with the following command and change my-project to your project name.

vue init webpack my-project

Next, you will be asked a series of questions:

  • Project name (yourprojectname) – The name must be URL friendly (no space)
  • Project description (A Vue.js project)
  • Author (SoftAuthor)
  • Vue build (Use arrow keys) ❯ Runtime + Compiler: recommended for most users
  • Install vue-router? (Y/N) ❯ Yes
  • Use ESLint to lint your code? (Y/N) ❯ No
  • Set up unit tests (Y/N) ❯ No
  • Setup e2e tests with Nightwatch? (Y/N) ❯ No
  • Should we run `npm install` for you after the project has been created? (recommended) (Use arrow keys) ❯ Yes, use NPM

Once you hit enter, it will start downloading and installing dependencies which will take a minute or two.

After that cd to your project.

cd yourprojectname


npm run dev 

At this stage, your project will be compiled and Vue will give you the localhost address. Go ahead and launch it on the browser.

If you already have a Gmail account, go to the Firebase Console and log in.

Once you have logged in, you will see the project explorer window like the image below.

⚠️ It may look a bit different depending on when you read this article.

Choose Add Project button

Create project name of your choice and click continue

Click Create Project

⚠️ I have disabled Enable Google Analytics for this project for demo purposes. Feel free to enable it if needed.

Choose Web Platform

You might not see this window for the second time onward. In that case, choose project overview at the top left -> Gear icon -> project settings -> Scroll down -> add app -> then choose the web platform from there.

Register App

Once you choose the web platform, it will take you to the Add Firebase to your web app page.

Give it a nick name and hit Register app

Add Firebase SDK – Javascript

If you have a plain JavaScript project, you can simply copy and paste the scripts below into the bottom of your HTML file above the end of body tag.

If you want to use any of the Firebase services such as Cloud Firestore, Authentication, you will need to add them manually below the core SDK library and above the configuration code.

You can find the additional Firebase SDK links here.

Add Firebase SDK Version 8 – Vue.js

1. install firebase to the vue project.

npm install firebase@8.3.2 --save

2. Import firebase inside the main.js file

import firebase from 'firebase'

3. Add just the configuration code inside the main.js after importing firebase but before the vue instance.

var firebaseConfig = {
    apiKey: "************************",
    authDomain: "************************",
    databaseURL: "************************",
    projectId: "************************",
    storageBucket: "************************",
    messagingSenderId: "************************",
    appId: "************************"
  // Initialize Firebase

Don’t forget to replace with your configuration code. 😜

There you have it!

Vue JS & Google Maps API