48

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 ?

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Abhilasha
  • 949
  • 3
  • 9
  • 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

4 Answers4

115

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.

  1. Go to this URL
  2. Select the project that the function is in
  3. Select a function from the list
  4. You will get to this page: Source tab of Google Cloud Functions

  5. Select the Source at the top

  6. 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.

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
  • I am getting 404 after clicking on that link. On the page you added above inside code preview section I am getting this message : Archive not found in the storage location – Abhilasha May 11 '17 at 14:04
  • I had deployed it using firebase deploy command from my local machine – Abhilasha May 11 '17 at 14:17
  • Hmm... in that case the functions source might have been deleted from the Cloud servers too. – Frank van Puffelen May 11 '17 at 14:27
  • 1
    If 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
  • Rule #1 for building a platform: Assume `git reset --hard` will happen waylessly – deepelement Jan 23 '19 at 00:42
  • 1
    Lifesaver for my own incompetence. – MQLN Feb 06 '19 at 02:53
  • 1
    You saved my day. Thanks. – AFMeirelles Jan 09 '20 at 20:25
  • Thank you so much! – Alex Ironside Jan 18 '21 at 11:35
2

When you click to select your project, make sure you have the right organization selected.

Select Organization

Clinton
  • 803
  • 6
  • 13
1

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.

Allan
  • 2,593
  • 2
  • 24
  • 38
-3

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.

  1. Goto https://console.cloud.google.com/storage/
  2. Choose the bucket staging.<project-name>.appspot.com
  3. Click on firebase-functions-source file.

The zipped folder of your firebase functions will get downloaded

Cheers!

shikhar bansal
  • 1,412
  • 2
  • 17
  • 40