Help us understand the problem. What is going on with this article?

Google Cloud Functions Emulatorの備忘録

More than 1 year has passed since last update.

最近Firebaseでcloud functionsを使用することが多く、Cloud Functions Emulatorで試す際に毎回つまってたのでその備忘録

インストール

npm
npm install -g @google-cloud/functions-emulator
yarn
yarn global add @google-cloud/functions-emulator

インストールができればfunctionsコマンドが使用できるようになるのですがzshの方は競合してしまうのでfunctions-emulatorに置き換えてください。

エミュレータの起動
functions start
※起動のエラーで毎回つまる。。

ERROR: Error: Emulator crashed! Check the log file...
    at ChildProcess.child.on (/Users/kohei/.npm-global/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:650:24)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)

こちらパーミッションの問題なのでsudoつけて解決

sudo functions start

関数
index.tsに関数追加

index.ts
exports.hoge = functions.https.onRequest((request, response) => {
     console.log("hogehoge"))
     response.status(200).end()
})

ビルド
npm run build

関数のデプロイ

functions deploy デプロイする関数 --trigger-http

デプロイするとアクセスURLが貼られるのでアクセスして確認

ログ確認
functions logs read

エミュレータの停止
functions stop

kohei1218
主にiOS、たまにAndroid、Rails、ごくまれにLaravel
uzabase
企業活動の意思決定を支える情報インフラの提供
https://www.uzabase.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした