Reputation: 23151
In a Node.js script, How can I check if I'm running in Google Cloud VM or locally?
I'm not using Google App Engine.
Is it possible to do this without making any network requests, synchronously?
Upvotes: 1
Views: 1989
Reputation: 2604
Edit /etc/environment
on the VM, append the following:
GCLOUD=1
And then in Node:
const isRunningInVM = Boolean(process.env.GCLOUD)
Upvotes: 2
Reputation: 20219
You could, for example, check for the various environment variables that will be set, such as GOOGLE_CLOUD_PROJECT
or GAE_INSTANCE
, accessible from a Node.js script as:
process.env.GOOGLE_CLOUD_PROJECT
Upvotes: 3