I have a subscription-based android app which required the used of firebase cloud functions for notification schedule.
Now I am confused about where should I create the functions directory? Should I make it in the android project directory itself or make a separate project directory for it?
Where should I create the functions directory?
You should create it as a sub-folder (or sub-directory) of your Firebase project folder. This way you will be able to deploy it with firebase deploy ....
If you didn't choose to add Cloud Functions when you created your Firebase project, you can run firebase init functions in the terminal under your Firebase project main folder.
More info here.
Related
When initializing a firebase project, it creates a firebase.json file containing settings for hosting, firestore, storage, but nothing for functions. When deploying, the firebase CLI correctly finds the functions. Does the CLI goes through the whole project looking for functions or does it store the functions' folder path somewhere?
The Firebase CLI by default assumes that the Cloud Functions for your projects are in a functions folder under the project folder.
You can override this by specifying a source value in the functions configuration in firebase.json.
Also see Doug's answer here: How to deploy functions from other directory than '/functions'?
I experimented with firebase functions for the init part and it has created a folder for me. Now when I deploy each time it also picks up the functions folder. When I remove the functions folder I get an error, when deploying. How do I deploy everything but functions?
firebase deploy has a parameter --except . So to deploy everything except functions you can run:
firebase deploy --except functions
You can use the only option/flag, for example firebase deploy --only hosting,storage, see the CLI doc.
You can also use deploy targets which "are short-name identifiers (that you define yourself) for Firebase resources in your Firebase project".
Check to make sure that you have removed the implicit reference to the function in your index.js and then running firebase deploy should do the trick. If you want to explicitly delete the function completely, you can use the firebase functions:delete <myFunction> and then delete the functions folder. You can find more details in the doc here
I have created 2 separate projects in Firebase one for the TEST (development) and one for the actual PROD(unction) environment.
I have create a hosting project and am also using Firebase functions that I have successfully deployed and tested on the Firebase TEST project (using the command line as described in the docs).
What is the best / easiest way to now publish to the Firebase PROD project?
Get familiar with the way the Firebase CLI lets you attach a workspace to multiple projects. You can use firebase use --add on the command line to add a project alias, then firebase use [project] to switch between projects for deployment.
You can find the documentation for managing aliases here.
When I first setup my firebase project and ran firebase init I didn't think i'd host a site. So I didn't check the hosting on setup.
And so i have an ios project with the following folder structure:
myproject:
- ios (xcode code)
- firebase
- functions
- index.js (i have cloud functions already deployed from here)
If I run firebase init again can i just select "hosting" so that a public folder is added without overwriting everything in the functions folder?
You can tell the CLI to only initialize hosting with:
firebase init hosting
That way your other settings will remain unmodified.
So I’m testing out the CLI today and firebase init with db/hosting selected, and choosing to create a new project, always says Error: Permission denied..
sudo firebase init didn’t help.
firebase-tools version 3.0.3 on OS X 10.11.5.
firebase init
You're about to initialize a Firebase project in this directory:
/Users/splaktar/Git/tmp
Before we get started, keep in mind:
* You are initializing in an existing Firebase project directory
? What Firebase CLI features do you want to setup for this folder? Database: Deploy Firebase Realtime Database Rules
=== Project Setup
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.
? What Firebase project do you want to associate as default? [don't setup a default project]
=== Database Setup
Firebase Realtime Database Rules allow you to define how your data should be
structured and when your data can be read from and written to.
? What file should be used for Database Rules? database.rules.json
Error: Permission denied.
I've tried the answers here but they did not help. Is this just a bug in the firebase-tools?
I have the same issue and this is how I fixed it.
run firebase init
Deselect ❯◯ Database: Deploy Firebase Realtime Database Rules
Go through other steps to setup the initial app, selecting the default for each should work just fine.
run firebase serve
Hope that helps.
Sometimes it could happen when .firebaserc file exists.
Remove .firebaserc file and reattempt firebase init.
I was with the same problem, but I was not accessing the right account.
After accessed the right account, I created a new project and run "firebase list" (before this not happened) and my new project was there.
This solved my problem.
You need to have Owner or Editor IAM permission on the GCP project to use firebase init command.
The firebase init command initializes/enables the project to use Cloud Functions/Hosting etc for Firebase. Owners/Editors have higher permissions that allow APIs to be enabled etc.
it is a first-time task when you starting the development, and then init command can be avoided if you have set up your cloud functions code in VCS for multiple developers or you.
i.e, Usually after writing code, you will replicate the project to other developers, who will then also write code and use firebase use yourprojectid further.