Quick Start Firebase using Node JS

nodefiend

chowderhead

Posted on April 28, 2019

Quick Start Firebase using Node JS

Photo cred: Fancy crave

Purpose:

This guide will get you up and running with a a very simple Node API firebase backend.

  1. create a firebase project, click goto console , set it up with all default settings .

alt text

  1. Select default settings for creating new project

alt text

  1. Create a directory where you want to load our firebase project (and navigate to it ):

Sites/firebase_project

  1. Make sure you are inside the new directory of our firebase_project

  2. If you don't have it installed on your machine, install firebase global package

npm install -g firebase-tools
Enter fullscreen mode Exit fullscreen mode
  1. if you have never done this before and are not logged in then type: firebase login

6a. this will open up browser window where it will ask you to login to your google account.

Navigate back to your firebase_project directory and type this:

firebase init

Enter fullscreen mode Exit fullscreen mode
  1. in the command line you will see options , use the arrow keys to select: Functions: Configure and deploy Cloud Functions and press spacebar to select it

  2. now press enter

    1. when it asks for language, click Javascript.
    2. if it asks for ESLINT, press no (unless you want to get bugged often)
    3. when it asks to install , dependences click yes,

if you get an error check to make sure your directory has the correct permissions.

if you are still getting an error run firebase init --debug mode , this will help you see any errors that may appear.

  1. Navigate to functions/index.js and uncomment this :
exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
});

Enter fullscreen mode Exit fullscreen mode
  1. Now from the terminal, inside of the directory run :
firebase deploy
Enter fullscreen mode Exit fullscreen mode

After you deploy, you should get a URL like the one seen below:

helloworld

Now paste this link that you see in the terminal , into your favourite HTTP request tool, fore example (POSTMAN) and try to hit the URL, and see if you get "Hello from Firebase!"

Congratz!

This is your first node js request endpoint, you can assign a route to it , or add whatever youd like!

💖 💪 🙅 🚩
nodefiend
chowderhead

Posted on April 28, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related