How do I switch apps from the firebase cli?

2020-02-17 03:47发布

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?

5条回答
▲ chillily
2楼-- · 2020-02-17 04:27

Found some useful information here Firebase CLI Reference.

The following code works for me.

firebase use <project_id>
查看更多
放荡不羁爱自由
3楼-- · 2020-02-17 04:32

to change firebase app destination project you can type "firebase use myProjectName" . i also used the above answeres "firebase list" to check what project i have ( work for me in firebase cli 7.4 with angular 7 app)

查看更多
淡お忘
4楼-- · 2020-02-17 04:37

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
查看更多
Melony?
5楼-- · 2020-02-17 04:37

you can just use a command line switch

--project=my-firebase-project
查看更多
forever°为你锁心
6楼-- · 2020-02-17 04:44

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.

查看更多
登录 后发表回答