0

I have 2 different projects that I'm working on concurrently. I worked on the 1st project and have a native index.js file for that project. Then, I wanted to write Cloud Functions' code for the 2nd project. So, when I typed 'firebase init functions', it is saying that there's a default project that's selected (even after typing "firebase use project-id"). How do I rectify this?

PS: I completed the whole sequence once and the index.js file got overwritten. Luckily for me, I had a back up for the 1st project.

Edit 2: I changed directories and created a project but it overwrote the index.js file once again in the 'functions' folder. How to fix this? Should I navigate out of the home directory itself?

enter image description here

Arjun Ram
  • 369
  • 2
  • 18

2 Answers2

1

Configure Multiple Projects

The Web and Admin SDKs are configured by directly passing values to their initialization functions. For these SDK, you can use a runtime check to select development or production configuration variables.

On your development machine / project build out each app under a unique folder.

Community
  • 1
  • 1
Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91
  • Thanks but this is not what my question is about! – Arjun Ram Jun 14 '18 at 15:27
  • Can't you firebase init from within each projects unique (sub)folder? ...Like initializing git in subfolders? ...That's what it looks like you are needing to do since (each projects) cloud functions take a single index.js. – Ronnie Royston Jun 14 '18 at 19:02
  • But the thing is if the subholder is in the home folder, it is creating the new project by overwriting the index.js. – Arjun Ram Jun 15 '18 at 04:18
0

I am not 100% sure to understand the problem but here are two possible scenarios:

1/ You are working in a specific project, writing Cloud Functions (i.e. modifying the index.js file) and you want to work on another totally different project. Just create a new directory (outside of the current project) and initialize a new project there, as explained in the doc here: "https://firebase.google.com/docs/cli/#initializing_a_project_directory"

2/ You are working in a specific project, writing Cloud Functions (i.e. modifying the index.js file) and you want to deploy the same code to another Firebase project. Just do firebase use <alias_or_project_id> as you have mentioned and then firebase deploy (or firebase deploy --only functions). Of course, in this scenario, you may need to adapt some other parts of your code when swapping from one project to the other, like for example the JavaScript config object.

If this answer does not answer your problem, please give some more details.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • How can it overwrite a file in the newly created `Guduapp` directory you have just created?? Not sure to understand. – Renaud Tarnec Jun 14 '18 at 14:58
  • It's not. It's overwriting it in the parent directory. So even if I change the path, it's creating the project in the home directory if you know what I mean. – Arjun Ram Jun 14 '18 at 15:26