— nodejs, firebase — 1 min read
We are going to just get on setting new firebase project using Functions.
1firebase login2
3firebase projects:list4
5firebase init6-- You can select the project here7(or)8firebase use --add9-- You can add project later by this technique
This should create a functions folder in the current folder
Now, there are multiple ways to organize firebase functions as per Google Firebase Docs
I am going with the 3rd option as it doesn't need node_modules
folder under each function/repo folder. Its just centralized.
Main index.js file
1const functions = require("firebase-functions");2const admin = require('firebase-admin');3
4admin.initializeApp(functions.config().firebase);5
6// Local Requires7const hello = require('./helloWorld');8exports.helloWorld = hello.World;
Local file
1const functions = require("firebase-functions");2
3// Create and Deploy Your First Cloud Functions4// https://firebase.google.com/docs/functions/write-firebase-functions5//6exports.World = functions.https.onRequest((request, response) => {7 functions.logger.info("Hello logs!", {structuredData: true});8 response.send("Hello from Firebase!");9});
Firebase commands
1-- #Testing2firebase emulators:start3-- Wait for 2-3 minutes. It should the link for function like below4-- http://localhost:5001/btd-in3-20220830/us-central1/helloWorld5
6-- (or)7
8firebase serve --only functions9
10-- #Deploying11firebase deploy --only functions:helloWorld