2

How do I tell if my process is running in a Google Cloud Function?

1
  • 1
    Not sure if there's a in-built property, but you can always initialize your function with some env and check for that. Commented Jun 15, 2020 at 13:13

1 Answer 1

2

I have 2 checks in mind:

  • Firstly, if the Cloud Function env variables are set (your other question)
  • Secondly, you can check if the metadata server answer by performing a get request to it. Don't forget the header (Metadata-flavor: google). If you get a Http status code 404, you aren't on Cloud Function.
Sign up to request clarification or add additional context in comments.

1 Comment

I am running NodeJS 10 so I am using if (process.env.K_SERVICE). Also for whoever comes later, __filename does not give the service name.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.