Kannkyo Day's

ソフトウェアエンジニアの日常系ブログ

Firebaseのつかいかた

はじめに

Firebaseの使い方の記事がいくつかあるが、バージョンが変わったせいか振る舞いが違っている・・・。 ので改めて使い方をまとめる。

インストール

$ npm install --global firebase-tools

ログイン

$ firebase login
? Allow Firebase to collect anonymous CLI usage and error reporting information? No

Visit this URL on any device to log in:
https://accounts.google.com/xxx
Waiting for authentication...

✔  Success! Logged in as xxxx@gmail.com

ローカル・プロジェクト新規作成

$ firebase init

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  path/firebase/prject_name

Before we get started, keep in mind:

  * You are currently outside your home directory

? Which Firebase CLI features do you want to setup for this folder? Press Space to select features, then Enter to confirm your choices. Functions: Configure and deploy 
Cloud Functions

=== 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.

? Select a default Firebase project for this directory: [create a new project]

=== Functions Setup

A functions directory will be created in your project with a Node.js
package pre-configured. Functions can be deployed with firebase deploy.

? What language would you like to use to write Cloud Functions? JavaScript
? Do you want to use ESLint to catch probable bugs and enforce style? No
✔  Wrote functions/package.json
✔  Wrote functions/index.js
✔  Wrote functions/.gitignore
? Do you want to install dependencies with npm now? Yes

> grpc@1.19.0 install path/firebase/project_name/functions/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library

node-pre-gyp WARN Using request for node-pre-gyp https download 
[grpc] Success: "path/firebase/project_name/functions/node_modules/grpc/src/node/extension_binary/node-v67-linux-x64-glibc/grpc_node.node" is installed via remote

> protobufjs@6.8.8 postinstall path/firebase/project_name/functions/node_modules/protobufjs
> node scripts/postinstall


> firebase-functions@2.2.0 postinstall path/firebase/project_name/functions/node_modules/firebase-functions
> node ./upgrade-warning


======== WARNING! ========

This upgrade of firebase-functions contains breaking changes if you are upgrading from a version below v1.0.0.

To see a complete list of these breaking changes, please go to:

https://firebase.google.com/docs/functions/beta-v1-diff

npm notice created a lockfile as package-lock.json. You should commit this file.
added 352 packages from 265 contributors and audited 1097 packages in 7.463s
found 0 vulnerabilities


i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...
i  Writing gitignore file to .gitignore...

✔  Firebase initialization complete!

Project creation is only available from the Firebase Console
Please visit https://console.firebase.google.com to create a new project, then run firebase use --add

クラウド・プロジェクト作成

ウェブサイト上でプロジェクトを追加する。

https://console.firebase.google.com

ローカル・プロジェクトにクラウド・プロジェクトを設定

$ firebase use --add
? Which project do you want to add? project_name
? What alias do you want to use for this project? (e.g. staging) project_name_alias

Created alias project_name_alias for project_name.
Now using alias project_name_alias (project_name)

デバッグ

$ sudo firebase serve --only functions