I had created firebase functions in nodejs and deployed the code on firebase. The function was to send an email when the new user is created. I have lost the code now. Can we pull that code from firebase ?

- 565,676
- 79
- 828
- 807

- 1,177
- 4
- 10
- 17
-
Try to do what i did on the similar [issue](https://stackoverflow.com/questions/46797662/retrieving-an-old-version-of-a-google-cloud-function-source) that i had – Ariel Nov 03 '17 at 22:18
6 Answers
Note: the process below may work or not for your case. Don't rely on it as a replacement for keeping your code in a proper version control system.
You can retrieve the code for your Cloud Functions from the Cloud Console.
- Go to this URL
- Select the project that the function is in
- Select a function from the list
Select the Source at the top
- Click the "Source location" link
A zip file with the latest source of your function will start to download.
Note that these files may periodically get deleted. In that case, the above process will not work to recover your source code.

- 565,676
- 79
- 828
- 807
-
1If you are a collaborator on a project, it might not show up in the GCP dashboard. If you go to the Firebase dashboard, go to the functions directory, and go to one of the functions, off to the right there's a vertical ellipsis that only appears when you hover over it. Click that, and select "Detailed Usage Stats" - that will take you to the GCP dashboard for the project, and then you can follow these instructions. – kodi Mar 23 '18 at 15:10
In the firebase console in the left hand menu select Functions. Hover over the function you want to view and click the three vertical dots. Select Detailed Usage Stats. This will bring you to the Google Cloud console. Select 'Source' to get the source code.

- 2,889
- 2
- 27
- 38
The google cloud console link didn't work for me (might have been outdated)
Updated
- Go to https://console.cloud.google.com/
- Select your project [1]
- Go to https://console.cloud.google.com/functions/list
- Under Actions (with the 3 dots), click Test Function [2]
- Go to Source, and you will be able to see your entire deployed project functions [3]

- 11
- 1
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 05 '22 at 20:57
After downloading the source using the method of the selected answer, you need to perform the following tasks to be able to create/edit functions.
- Create a new folder. eg, myFunctions.
- cd into myFunctions.
- run firebase init.
- Follow the onscreen instructions. Be sure to select "Cloud Functions" in the list of firebase features to initialise. Also be sure to choose existing project & choose your project.
- After npm finishes, a functions folder will be created in myFunctions.
- Delete the functions folder.
- Copy the functions folder that you downloaded initially.
That should be the trick!

- 13
- 3
-
What if I have more than one function in firebase? if I download the source of each function what should I do next in order to be able to edit them? – santiago calvo Dec 16 '22 at 15:06
It looks like that the answers given above are outdated and do not work anymore. This is the latest and most robust thalaiva way of accomplishing the task assigned to you in this tight deadline.
- Goto https://console.cloud.google.com/storage/
- Choose the bucket
staging.<project-name>.appspot.com
- Click on
firebase-functions-source
file.
The zipped folder of your firebase functions will get downloaded
Cheers!

- 1,629
- 2
- 21
- 43