संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Cloud Functions for Firebase
plat_ios
plat_android
plat_web
plat_flutter
plat_cpp
plat_unity
Cloud Functions for Firebase, सर्वरलेस फ़्रेमवर्क है. इसकी मदद से, बैकग्राउंड इवेंट, एचटीटीपीएस अनुरोधों,
Admin SDK या
Cloud Scheduler जॉब से ट्रिगर होने वाले इवेंट के जवाब में, बैकएंड कोड अपने-आप चलाया जा सकता है. आपका JavaScript, TypeScript या Python कोड, Google Cloud के इंफ़्रास्ट्रक्चर पर सेव होता है. साथ ही, यह मैनेज किए जा रहे एनवायरमेंट में काम करता है. आपको अपने सर्वर को मैनेज और स्केल करने की ज़रूरत नहीं है.
क्या Google Cloud में Cloud Functions का इस्तेमाल पहले से किया जा रहा है?
Firebase किस तरह काम करता है, इसके बारे में ज़्यादा जानें.
शुरू करें
इस्तेमाल के उदाहरण
मुख्य सुविधाएं
Firebase की सुविधाओं को इंटिग्रेट करता है और Firebase को Google Cloud से कनेक्ट करता है |
आपके लिखे गए फ़ंक्शन, Firebase और Google Cloud की अलग-अलग सुविधाओं से जनरेट होने वाले इवेंट के लिए काम कर सकते हैं. जैसे, Firebase Authentication ट्रिगर से लेकर Cloud Storage ट्रिगर तक.
Cloud Functions के साथ Admin SDK का इस्तेमाल करके, Firebase की सभी सुविधाओं को इंटिग्रेट करें. साथ ही, अपने वेबहुक लिखकर तीसरे पक्ष की सेवाओं के साथ इंटिग्रेट करें.
Cloud Functions छोटे-मोटे बदलाव वाले कोड को कम करता है. इससे, अपने फ़ंक्शन में Firebase और Google Cloud का इस्तेमाल करना आसान हो जाता है. |
कोई रखरखाव नहीं |
कमांड लाइन से एक कमांड देकर, अपने JavaScript, TypeScript या Python कोड को हमारे सर्वर पर डिप्लॉय करें.
इसके बाद, Firebase आपके ऐप्लिकेशन के इस्तेमाल के पैटर्न के मुताबिक कंप्यूटिंग रिसोर्स को अपने-आप स्केल अप करता है. आपको कभी क्रेडेंशियल, सर्वर कॉन्फ़िगरेशन, नए सर्वर की प्रोविजनिंग या पुराने सर्वर की सुविधा बंद होने की चिंता नहीं रहती है. |
आपके लॉजिक को निजी और सुरक्षित बनाए रखता है |
कई मामलों में, डेवलपर ऐप्लिकेशन के लॉजिक को सर्वर पर कंट्रोल करना पसंद करते हैं, ताकि क्लाइंट साइड पर होने वाली छेड़छाड़ से बचा जा सके. इसके अलावा, कभी-कभी
यह भी ज़रूरी होता है कि उस कोड को रिवर्स इंजीनियरिंग की अनुमति न दी जाए.
Cloud Functions, क्लाइंट से पूरी तरह अलग है, ताकि आप यह पक्का कर सकें कि यह निजी है और हमेशा वही काम करता है जो आपको चाहिए. |
यह कैसे काम करता है?
फ़ंक्शन लिखने और उसे डिप्लॉय करने के बाद, Google के सर्वर तुरंत फ़ंक्शन को मैनेज करना शुरू कर देते हैं. फ़ंक्शन को सीधे तौर पर एचटीटीपी अनुरोध, Admin SDK या शेड्यूल किए गए जॉब से ट्रिगर किया जा सकता है. बैकग्राउंड फ़ंक्शन के मामले में, Google के सर्वर इवेंट सुनते हैं और ट्रिगर होने पर फ़ंक्शन को चलाते हैं.
लोड बढ़ने या कम होने पर, Google आपके फ़ंक्शन को चलाने के लिए ज़रूरी वर्चुअल सर्वर इंस्टेंस की संख्या को तेज़ी से बढ़ाता या घटाता है. हर फ़ंक्शन अलग से काम करता है. यह अपने कॉन्फ़िगरेशन के साथ अपने एनवायरमेंट में काम करता है.
बैकग्राउंड फ़ंक्शन की लाइफ़साइकल
- आपको एक नए फ़ंक्शन के लिए कोड लिखना होगा. इसके लिए, आपको इवेंट प्रोवाइडर (जैसे कि Cloud Firestore) चुनना होगा. साथ ही, आपको वे शर्तें तय करनी होंगी जिनके तहत फ़ंक्शन को लागू किया जाना चाहिए.
- फ़ंक्शन डिप्लॉय करने पर:
- Firebase सीएलआई, फ़ंक्शन कोड का
.zip
संग्रह बनाता है. इसके बाद, इसे Cloud Storage बकेट में अपलोड किया जाता है. इस बकेट के नाम की शुरुआत gcf-sources
से होती है. इसके बाद, Cloud Functions आपके प्रोजेक्ट में Artifact Registry रिपॉज़िटरी बनाता है. इस रिपॉज़िटरी का नाम gcf-artifacts
होता है.
- Cloud Build फ़ंक्शन कोड को वापस लाता है और फ़ंक्शन का सोर्स बनाता है. Cloud Build लॉग, Google Cloud कंसोल में देखे जा सकते हैं.
- बनाए गए फ़ंक्शन के कोड की कंटेनर इमेज, आपके प्रोजेक्ट में मौजूद Artifact Registry नाम की निजी
gcf-artifacts
रिपॉज़िटरी में अपलोड की जाती है. इसके बाद, आपका नया फ़ंक्शन रोल आउट कर दिया जाता है.
- जब इवेंट प्रोवाइडर ऐसा इवेंट जनरेट करता है जो फ़ंक्शन की शर्तों से मेल खाता है, तब कोड को चालू किया जाता है. फ़ंक्शन से एक सेवा खाता जुड़ा होता है. इसका इस्तेमाल, Firebase Admin SDK की मदद से Firebase की अन्य सेवाओं को ऐक्सेस करने के लिए किया जा सकता है.
- अगर फ़ंक्शन कई इवेंट मैनेज कर रहा है, तो Google काम को तेज़ी से पूरा करने के लिए ज़्यादा इंस्टेंस बनाता है. अगर फ़ंक्शन का इस्तेमाल नहीं किया जा रहा है, तो इंस्टेंस हटा दिए जाते हैं.
- अपडेट किए गए कोड को डिप्लॉय करके फ़ंक्शन को अपडेट करने पर, पुराने वर्शन के इंस्टेंस और Artifact Registry में मौजूद बिल्ड आर्टफ़ैक्ट मिटा दिए जाते हैं. इसके बाद, उनकी जगह नए इंस्टेंस ले लेते हैं.
- फ़ंक्शन मिटाने पर, सभी इंस्टेंस और ज़िप संग्रह मिट जाते हैं. साथ ही, Artifact Registry में मौजूद, उनसे जुड़े बिल्ड आर्टफ़ैक्ट भी मिट जाते हैं.
फ़ंक्शन और इवेंट प्रोवाइडर के बीच कनेक्शन हट जाता है.
बैकग्राउंड फ़ंक्शन के साथ इवेंट सुनने के अलावा, एचटीटीपी अनुरोध या क्लाइंट से कॉल करके फ़ंक्शन को सीधे तौर पर कॉल किया जा सकता है. Admin SDK के ज़रिए, फ़ंक्शन को किसी तय शेड्यूल पर ट्रिगर किया जा सकता है या टास्क फ़ंक्शन को कतार में लगाया जा सकता है.
लागू करने का तरीका
|
Cloud Functions सेट अप करें |
Firebase CLI इंस्टॉल करें और अपने Firebase प्रोजेक्ट में Cloud Functions को शुरू करें. |
|
फ़ंक्शन लिखना |
Firebase सेवाओं, Google Cloud सेवाओं या इवेंट की अन्य सेवाओं से इवेंट मैनेज करने के लिए, JavaScript कोड, TypeScript कोड या Python कोड लिखें. |
|
टेस्ट फ़ंक्शन |
अपने फ़ंक्शन की जांच करने के लिए, लोकल एम्युलेटर का इस्तेमाल करें. |
|
डिप्लॉय और मॉनिटर करना |
अपने प्रोजेक्ट को इस्तेमाल के हिसाब से शुल्क चुकाने वाले Blaze प्लान पर अपग्रेड करें. इसके बाद, Firebase CLI का इस्तेमाल करके अपने फ़ंक्शन डिप्लॉय करें. इसके बाद, अपने लॉग देखने और उनमें खोजने के लिए,
Google Cloud कंसोल
का इस्तेमाल किया जा सकता है. |
अगले चरण
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-17 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-08-17 (UTC) को अपडेट किया गया."],[],[],null,["Cloud Functions for Firebase \nplat_ios plat_android plat_web plat_flutter plat_cpp plat_unity \nCloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by background events, HTTPS requests, the Admin SDK, or Cloud Scheduler jobs. Your JavaScript, TypeScript or Python code is stored on Google Cloud infrastructure and runs in a managed environment. There's no need to manage and scale your own servers.\n\n\u003cbr /\u003e\n\nAlready using Cloud Functions in Google Cloud?\n[Learn more](/docs/functions/functions-and-firebase) about how Firebase fits\ninto the picture.\n\n[Get started](/docs/functions/get-started)\n[Use cases](/docs/functions/use-cases)\n\nKey capabilities\n\n|----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Integrates Firebase features and connects Firebase with Google Cloud | The functions you write can respond to events generated by various Firebase and Google Cloud features, from [Firebase Authentication triggers](/docs/functions/auth-events) to [Cloud Storage Triggers](/docs/functions/gcp-storage-events). Integrate across Firebase features using the [Admin SDK](/docs/admin/setup) together with Cloud Functions, and integrate with third-party services by writing your own webhooks. Cloud Functions minimizes boilerplate code, making it easier to use Firebase and Google Cloud inside your function. |\n| Zero maintenance | Deploy your JavaScript, TypeScript, or Python code to our servers with one command from the command line. After that, Firebase automatically scales up computing resources to match the usage patterns of your users. You never worry about credentials, server configuration, provisioning new servers, or decommissioning old ones. |\n| Keeps your logic private and secure | In many cases, developers prefer to control application logic on the server to avoid tampering on the client side. Also, sometimes it's not desirable to allow that code to be reverse engineered. Cloud Functions is fully insulated from the client, so you can be sure it is private and always does exactly what you want. |\n\nHow does it work?\n\nAfter you write and deploy a function, Google's servers begin to manage the\nfunction immediately. You can fire the function directly with an HTTP request,\nthe Admin SDK, or a scheduled job, or, in the case of background functions,\nGoogle's servers listen for events and run the function when it is\ntriggered.\n\nAs the load increases or\ndecreases, Google responds by rapidly scaling the number of virtual server\ninstances needed to run your function. Each function runs in isolation, in its\nown environment with its own configuration.\n\nLifecycle of a background function\n\n1. You write code for a new function, selecting an event provider (such as Cloud Firestore), and defining the conditions under which the function should execute.\n2. When you deploy your function:\n 1. The Firebase CLI creates a `.zip` archive of the function code, which is then uploaded to a Cloud Storage bucket (prefixed with `gcf-sources`) before Cloud Functions creates an Artifact Registry repository (named `gcf-artifacts`) in your project.\n 2. Cloud Build retrieves the function code and builds the function source. You can view Cloud Build logs in the [Google Cloud console](//console.cloud.google.com/logs/query;query%3Dresource.type%253D%2522build%2522&sa=D&ust=1597179510979000&usg=AFQjCNG2BmFrgWjGoP83WiMrB2TLLXpBEQ).\n 3. The container image for the built functions code is uploaded to a private Artifact Registry repository in your project (named `gcf-artifacts`), and your new function is rolled out.\n3. When the event provider generates an event that matches the function's conditions, the code is invoked. The function has a service account attached to it that can be used to access other Firebase services with the help of the Firebase Admin SDK.\n4. If the function is busy handling many events, Google creates more instances to handle work faster. If the function is idle, instances are cleaned up.\n5. When you update the function by deploying updated code, instances for older versions are cleaned up along with build artifacts in Artifact Registry, and replaced by new instances.\n6. When you delete the function, all instances and zip archives are cleaned up, along with related build artifacts in Artifact Registry. The connection between the function and the event provider is removed.\n\nIn addition to listening for events with a background function, you can call\nfunctions directly with an HTTP request or a\n[call from the client](/docs/functions/callable). You can also trigger functions\non a fixed [schedule](/docs/functions/schedule-functions) or\n[enqueue task functions](/docs/functions/task-functions) via the Admin SDK.\n\nImplementation path\n\n|---|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | Set up Cloud Functions | Install the Firebase CLI and initialize Cloud Functions in your Firebase project. |\n| | Write functions | Write JavaScript code, TypeScript code, or Python code to handle events from Firebase services, Google Cloud services, or other event providers. |\n| | Test functions | Use the [local emulator](/docs/functions/local-emulator) to test your functions. |\n| | Deploy and monitor | Upgrade your project to the [pay-as-you-go Blaze pricing plan](/pricing) and deploy your functions using the Firebase CLI. You can then use the [Google Cloud console](//console.cloud.google.com/functions/list) to view and search through your logs. |\n\nNext steps\n\n- [Get started](/docs/functions/get-started) setting up, creating, and deploying functions.\n- Learn more about [what you can do with functions](/docs/functions/use-cases).\n- Try the [Cloud Functions codelab](https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#0)."]]