d-_-b
d-_-b

Reputation: 23151

Node.js check if running locally or in google cloud VM?

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

Answers (2)

Dimitar Nestorov
Dimitar Nestorov

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

P Varga
P Varga

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

Related Questions