MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

compute/getInstance.js:22–48  ·  view source on GitHub ↗

* Prints information about a VM instance in the given zone in the specified project. * * @param {string} projectId - Project ID or project number of the Cloud project you want to use. * @param {string} zone - Name of the zone you want to use. For example: 'us-west3-b'. * @param {string} instance

(projectId, zone, instanceName)

Source from the content-addressed store, hash-verified

20 * @param {string} instanceName - Name of the VM instance you want to query.
21 */
22function main(projectId, zone, instanceName) {
23 // [START compute_instances_get]
24 /**
25 * TODO(developer): Uncomment and replace these variables before running the sample.
26 */
27 // const projectId = 'YOUR_PROJECT_ID';
28 // const zone = 'europe-central2-b'
29 // const instanceName = 'YOUR_INSTANCE_NAME'
30
31 const compute = require('@google-cloud/compute');
32
33 async function getInstance() {
34 const instancesClient = new compute.InstancesClient();
35
36 const [instance] = await instancesClient.get({
37 project: projectId,
38 zone,
39 instance: instanceName,
40 });
41
42 console.log(
43 `Instance ${instanceName} data:\n${JSON.stringify(instance, null, 4)}`
44 );
45 }
46 getInstance();
47 // [END compute_instances_get]
48}
49
50process.on('unhandledRejection', err => {
51 console.error(err.message);

Callers 1

getInstance.jsFile · 0.70

Calls 1

getInstanceFunction · 0.70

Tested by

no test coverage detected