プログラミング学習

エミュレーターのインストール(firebase emulators:start)【Cloud Functionsローカル環境の確認】

プログラミング学習

Cloud Functionsローカル環境の確認方法を2点ほど。動画にリンクもしました。

エミュレーターのインストール(firebase emulators:start)【Cloud Functionsローカル環境の確認】

1つ目はエミュレーターを使う方法。インストールします。

firebase -version
firebase init(firebase init emulatorという短縮コマンドもあるらしい)
Emulators: Set up local emulators for Firebase featuresにチェック
❯◉ Functions
◯ Firestore
◯ Database
◯ Hosting
◯ Pubsub

お試しでfunctionsだけ入れてみました。

=== Emulators Setup
? Which Firebase emulators do you want to set up? Press Space to select emulators, then Enter to confirm your choices. Functions
? Which port do you want to use for the functions emulator? 5001
? Would you like to enable the Emulator UI? Yes
? Which port do you want to use for the Emulator UI (leave empty to use any available port)? NaN
? Would you like to download the emulators now? Yes
i  ui: downloading ui-v1.1.1.zip...

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

✔  Firebase initialization complete!

デフォルトのポート番号の割り当ては公式に説明があります。そのままにしました。

Local Emulator Suite のインストール、構成、統合  |  Firebase Local Emulator Suite

インストール完了後、firebase.jsonに次が追加

  "emulators": {
    "functions": {
      "port": 5001
    },
    "ui": {
      "enabled": true
    }
  }

次のコマンドが使えるようになっています。リンク先に飛べばOKです。

firebase emulators:start

終了はおなじみのcommand+Cです。

firebaseの公式から動画がでています。1:38あたりから見ます。

firebaseのバージョン9から少しやり方が変わったようです。そちら都合によりまだ試していません。

スポンサーリンク

nodeのコマンドで確認

cd functions
node index.js

ただ、node index.jsではhostsとのつなぎの部分は確認できません。最終確認はデプロイが必要です。

コメント

タイトルとURLをコピーしました