How do I tell if my process is running in a Google Cloud Function?
1 Answer
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.
1 Comment
Greg Finzer
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.