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
- Open the firebase console and create a project.
- Verify that you have installed the latest version of NodeJs in your system.
- 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
- Open up the terminal and type
firebase login
- Authenticate from the browser or click the generated link on the terminal.
Setting up firebase project on local
- Initialize firebase project, open the terminal, and type
firebase init
- Move the cursor
↓
to Functions andspace
to select (*) and hitenter⏎
Do the following little things.
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
Write Hello world project
- Install Express inside the
functions
folder
npm i express
- Delete the
index.js
file from the functions folder.
- 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.
Setup firebase billing account
- Upgrade to
Blaze plan
.
- Now you can deploy your application.
Deploy
- Go to the firebase project folder.
firebase deploy
- Click the
Function URL
.
Finished
That's it for today!
Hope you liked the post, if you’ve got any questions your can Mail us at madhabapatra@gmail.com.
Thanks