FirebaseTools

What are the Firebase Tools, how to obtain them and a summary of the commands that they offer us to maintain, develop and deploy applications on Firebase.

Firebase Tools is a package of tools designed for the development of Firebase applications. They are useful and even essential when you are going to create applications, allowing you to perform various types of operations, such as serving a page locally or deploying an application.

We say essential, although the truth is that you could start developing without having the Firebase Tools. However, for Firebase hosting there is no FTP access, nor ssh or anything like that, so the only way to upload your files is by using the Firebase Tools.

Install firebase-tools

The first step will be to get the tools, which you install with npm, via command line:

npm install -g firebase-tools

Note: In this tutorial we work with the firebase-tools 3.x, so if you have the old Firebase Tools 2.x branch, you should update them.

This installation allows us to have the “firebase” command globally available, which in turn will have several sub-commands to do different things. You can start by running the help command to see everything that firebase-tools gives you:

firebase –help

Login / logout in Firebase

For many of the Firebase Tools commands you need to have permissions granted. Obviously a lot of operations work with your Firebase account and you need to be logged in.

There are two very simple commands, one of which you can run right now.

firebase login

This command will open a browser for you to give permissions to Firebase Tools, for which you will have to enter your Google account password, with which you enter the Firebase console.

See also  detect installed java

firebase logout

This command will be used to remove the permissions to firebase tools, something important in certain cases, because if you don’t, anyone with access to that computer would be able to perform any action with your applications.

embedded web server

As you know, for your pages to work with Firebase you need to access them through http, that is, through a web server. Now Firebase includes that server for you, so it saves you having to configure any other server on your computer. It is a simple server, with static files, but you will be able to use it perfectly since with Firebase there is no programming on the server side.

The command to launch the embedded web server is:

firebase server

If you launch it on any folder where you haven’t initialized an application, it will use that folder from where you launched it as “document root”. You will see that a message appears in English informing you of this situation. But by starting an application, as we will see below, you will prevent that warning message from appearing and you will also be able to configure the root of the server in other folders.

Initialize a Firebase application

Another of the more typical things you’ll want to do with Firebase is initialize an app. This step is essential to later be able to deploy that application on the hosting offered by Firebase.

We initialize the Firebase application with the command:

firebase init

This process will collect a series of information by command line, to configure your application.

See also  open_basedir problem on servers with Plesk

Note: In order to complete the process, you must have previously logged in with your Google account, as we have said before.

The first thing it tells you is to indicate what you want to initialize (What Firebase CLI features do you want to setup for this folder?), offering two possibilities, security rules and hosting. You can hit the spacebar to select or not select either option, although you’ll usually want both, so you hit enter.

It will then ask you which Firebase app you’ve created in the console that you want to associate with this app being initialized.

From there you will surely be able to provide other data that the command needs, but I am going to give you some tips, which if you are new to Firebase can answer any questions.

What file should be used for Database Rules?

Here it is asking you for the file where you are going to write the security rules locally. If you already have a file like “rules.json” or something similar, just point it to it. But BEWARE, in the next question he will ask you if you want him to overwrite it with an initial code, tell him no, so he doesn’t delete your current rules. If you do not have a rules file you can leave the option that appears by default “database.rules.json” by pressing enter. Then it will create such a file for you among those of your project.

What do you want to use as your public directory?

Here it is asking you about the publish root folder, or document root. You can indicate the place where you have your index.html, or if you want the folder that it proposes (public), in which case it will create it for you and place an initial index.html.

See also  internal links

Configure as a single-page app (rewrite all urls to /index.html)?

This is for you to indicate if your website is going to be a SPA (single page application) or single page application. You know, a web application where there’s only one index.html and all the application paths are actually served from the same file.

Once the firebase init is executed, it will create two files: firebase.json and .firebaserc that will contain the information entered in this process, in the formats that Firebase needs.

Deployment of an application

Now that you have your app initialized, you can deploy it to Firebase’s hosting servers. It’s free hosting that you can even use with your own domain name, which is very helpful (and generous).

The deploy is child’s play, since the necessary information to do it has been previously configured with the “firebase init”. You do it with this command:

firebase deploy

Now everything will be automatic and at the end you will see a message with the URL of the domain where you can see your website once published on the Firebase server.

There are other less necessary commands for day-to-day operations, within the Firebase Tools, I recommend that you consult the help or access to find more information.

Loading Facebook Comments ...
Loading Disqus Comments ...