How do I switch apps from the firebase cli?
Solution 1
Found some useful information here Firebase CLI Reference.
The following code works for me.
firebase use <project_id>
Solution 2
I rather use scripts. Consider a project structure like this:
your-project
├── .firebaserc
└── functions
├── package.json
└── index.js
Go to .firebaserc
and follow the next example
{
"projects": {
"default": "project-name",
"prod": "other-name"
}
}
Then go to package.json
and add the following scripts (changeToProd
, and changeToDev
).
{
...
"scripts": {
...
"changeToProd": "firebase use prod",
"changeToDev": "firebase use default"
},
"dependencies": {
...
},
...
}
If your IDE support npm scripts you can run them using the IDE UI, otherwise it can be run using the command console. Make sure you are inside the functions
folder.
npm run-script changeToProd
You can verify your current project by running the following command from the terminal or added to the scripts as we just did
firebase use
Solution 3
If you are using Node.js on windows, your answer should be
firebase use <project_id>
but without the <> for example
firebase use chat-app-2a150
You can use the following code to view all your projects so as to pick the correct project ID to use
firebase projects:list
Solution 4
2020:
The officially recommended way is to use "alias":
In your .firebaserc
, set different project IDs like this:
{
"projects": {
"production": "my-project-id",
"testing": "my-testing-project-id"
}
}
// you can also add them interactively with `firebase use --add`
Then switch projects in CLI with firebase use testing
, firebase use production
.
Note: switching projects won't create any git diff, it's simply remembered in your local machine. Use firebase use
to see which project is currently being used.
Uncommon cases:
- If you want to use your own ID without committing changes to the project owner's
.firebaserc
, dofirebase use my-own-id
locally as mentioned in the accepted answer. - If you want people to fork your code then use their own IDs, add
.firebaserc
into.gitignore
.
Solution 5
In the directory where you run firebase list
, there will be a file called firebase.json
. If you open that in a text editor, you will see the app name in there. You can change it there or delete firebase.json
to change the app.
Or save yourself the hassle of editing a text file and do as Jason says: use firebase init
.
wvm2008
Self taught programmer, carpenter, and investor. I appreciate cultures which foster creativity, disruptive thought, and mentorship. Bureaucracy is cancer.
Updated on February 02, 2022Comments
-
wvm2008 about 2 years
This seems like something which should be pretty easy to do, but for whatever reason, I'm being defeated.
I'm trying to use the firebase-tools CLI to interact with my database. I'm able to login without any trouble, and when I type
firebase list
, I get a list of all my current apps. It also tells me which app I'm currently connected to.My problem is, I want to connect to one of the other apps. I'm running queries on my staging app, and I need to run them on my production app. I can see the production app in the list, but I'm not finding any way to switch to that app.
Thoughts?
-
Shreyan Mehta almost 3 yearsif having issues listing projects use
firebase projects:list
-
-
Abhishek over 6 yearsIs there a change now? Because I cannot find the app name in firebase.json but can find it in .firebaserc.... Appreciate the clarification...
-
Frank van Puffelen over 6 yearsThe project name is indeed in
.firebaserc
now. -
Enric Ribas about 6 yearsMight be wrong but this doesn't seem to switch the database. Deploying will deploy to "current" project but it seems to still pull data from original database. Pretty damn dangerous if you're going use this to separate production from staging environments. Hope no one loses their prod data. :(
-
cutiko about 5 yearsWelcome, my approach is intended to be sharable with the rest of the team :)
-
Zectbumo about 5 yearsI'm having the same issue that @Enric described about accessing the default database while being on a different project. Is there some way to detect what project is being used on the client side so that I can change the config to initialize the app appropriately?
-
Jonathan about 4 yearsfirebase.googleblog.com/2016/07/… - for a quick reference
-
sultanmyrza over 3 yearsmake sure you change firebaseConfig ` // Your web app's Firebase configuration var firebaseConfig = { apiKey: "api-key", authDomain: "new-project.firebaseapp.com", databaseURL: "https:/new-project.firebaseio.com", projectId: "new-project-id", storageBucket: "xxxxxxxxxxx.appspot.com", messagingSenderId: "xxxxxx", appId: "xxxxxxxxxx", measurementId: "xxxxxxxx" }; // Initialize Firebase`
-
Randika Vishman almost 2 yearsI tried this out, and it works. Using this method prevents me from making silly mistakes of interchanging the environment wrongly.