Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I switch apps from the firebase cli?

People also ask

What is firebase CLI used for?

The Firebase CLI is a utility used to administer Firebase projects and perform tasks such as Realtime Database management tasks from the command-line of a terminal or command-prompt window. The Firebase CLI is also the method by which Firebase Cloud Functions are deployed and managed.

Which command is used to only deploy the application using firebase CLI?

The firebase init command creates a firebase. json configuration file in the root of your project directory. The firebase. json file is required to deploy assets with the Firebase CLI because it specifies which files and settings from your project directory are deployed to your Firebase project.

How do you know if I have firebase CLI installed?

Run firebase tools --version to check version. And as per the prompt, run npm install -g firebase-tools to update.


Found some useful information here Firebase CLI Reference.

The following code works for me.

firebase use <project_id>

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

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

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.


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 you can do firebase use testing or firebase use production to switch between projects.

Note that switching projects won't create any git diff, it's simply remembered in your local machine. To see which project is currently being used, do firebase use.

If you want to use your own ID without committing changes to the project owner's .firebaserc, do firebase use my-own-id locally as mentioned in the accepted answer. On the other hand, if you're the project owner and want to ensure people use their own project IDs, you should add .firebaserc into .gitignore.


you can just use a command line switch

--project=my-firebase-project

Addition @cutiko's answer

In package.json

"scripts": {
...
"prod": "echo \"Switch to Production environment\" && firebase use prod && npm run runtimeconfig",
"dev": "echo \"Switch to Development environment\" && firebase use default && npm run runtimeconfig"
...

npm run runtimeconfig to get custom config environment

In .firebaserc

{
  "projects": {
    "default":"{project-dev-id}",
    "prod": "{project-prod-id}"
  }
}