0
0
Firebasecloud~30 mins

Cloud Functions setup in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
Cloud Functions setup
📖 Scenario: You are building a simple backend for a mobile app using Firebase. You want to create a Cloud Function that responds to HTTP requests and returns a welcome message.
🎯 Goal: Set up a Firebase Cloud Function project, write a basic HTTP function, and deploy it.
📋 What You'll Learn
Initialize a Firebase Cloud Functions project
Create an HTTP Cloud Function named helloWorld
The function should respond with the text 'Hello from Firebase!'
Deploy the Cloud Function
💡 Why This Matters
🌍 Real World
Cloud Functions let you run backend code without managing servers. This is useful for adding custom logic to your app, like sending notifications or processing data.
💼 Career
Many companies use serverless functions like Firebase Cloud Functions to build scalable backends quickly. Knowing how to set up and deploy these functions is a valuable skill for cloud developers.
Progress0 / 4 steps
1
Initialize Firebase Cloud Functions project
Run firebase init functions in your project folder and select JavaScript as the language. Then create a file named index.js with an empty exports object: const functions = require('firebase-functions'); and exports = {};
Firebase
Need a hint?

Use firebase init functions to start the setup and create index.js with the required imports.

2
Add HTTP Cloud Function configuration
In index.js, add a new export named helloWorld that is a function using functions.https.onRequest. The function should take request and response parameters.
Firebase
Need a hint?

Use exports.helloWorld = functions.https.onRequest((request, response) => { }) to define the function.

3
Implement the function response
Inside the helloWorld function, use response.send to send the text 'Hello from Firebase!' back to the client.
Firebase
Need a hint?

Use response.send('Hello from Firebase!'); inside the function body.

4
Deploy the Cloud Function
Run firebase deploy --only functions:helloWorld in your terminal to deploy the helloWorld Cloud Function to Firebase.
Firebase
Need a hint?

Use the Firebase CLI command firebase deploy --only functions:helloWorld to deploy your function.