Deploy Node.js on Firebase

Deploy Node.js on Firebase

Fully explained step by step to deploy your node(express) application on firebase

Firebase is Google's platform that helps you quickly deploy your web apps, and provides NoSQL databases and file storage.

You only need a Gmail account.

Setup

  1. Open the firebase console and create a project.

image.png

  1. Verify that you have installed the latest version of NodeJs in your system.

image.png

  1. After that, you need to install Firebase CLI on the terminal.

For Windows users

npm install -g firebase-tools

For Linux or Mac users

npm install -g firebase-tools

Configure your firebase account

  1. Open up the terminal and type
firebase login
  1. Authenticate from the browser or click the generated link on the terminal.

image.png

Setting up firebase project on local

  1. Initialize firebase project, open the terminal, and type
firebase init

image.png

  1. Move the cursor to Functions and space to select (*) and hit enter⏎

image.png

Do the following little things.

image.png

Understanding the file structure

Root folder

2.functions folder is created which is the project folder of our firebase application

3.cd functions to change the directory

image.png

Write Hello world project

  1. Install Express inside the functions folder
npm i express
  1. Delete the index.js file from the functions folder.

image.png

  1. Create a file named index.js in the functions folder and open the file in any editor. 4. Write the following hello world program.
const functions = require("firebase-functions");
const express = require("express");
//  express app
const app = express();

app.get("/", (req, res) => {
  res.send("Hello World!");
});

//  export app to firebase functions
exports.helloWorld = functions.https.onRequest(app);

5.cd .. to go back to the root folder of firebase.

image.png

Setup firebase billing account

  1. Upgrade to Blaze plan.

image.png

  1. Now you can deploy your application.

image.png

Deploy

  1. Go to the firebase project folder.
firebase deploy
  1. Click the Function URL.

image.png

Finished

That's it for today!

Hope you liked the post, if you’ve got any questions your can Mail us at .

Thanks