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

Function main

compute/listImages.js:20–49  ·  view source on GitHub ↗

* Prints a list of all non-deprecated image names available in given project. * * @param {string} projectId - ID or number of the project you want to list images from

(projectId)

Source from the content-addressed store, hash-verified

18 * @param {string} projectId - ID or number of the project you want to list images from
19 */
20function main(projectId) {
21 // [START compute_images_list]
22 /**
23 * TODO(developer): Uncomment and replace these variables before running the sample.
24 */
25 // const projectId = 'YOUR_PROJECT_ID';
26
27 const compute = require('@google-cloud/compute');
28
29 async function listImages() {
30 const imagesClient = new compute.ImagesClient();
31
32 // Listing only non-deprecated images to reduce the size of the reply.
33 const images = imagesClient.listAsync({
34 project: projectId,
35 maxResults: 3,
36 filter: 'deprecated.state != DEPRECATED',
37 });
38
39 // Although the `maxResults` parameter is specified in the request, the iterable returned
40 // by the `listAsync()` method hides the pagination mechanic. The library makes multiple
41 // requests to the API for you, so you can simply iterate over all the images.
42 for await (const image of images) {
43 console.log(` - ${image.name}`);
44 }
45 }
46
47 listImages();
48 // [END compute_images_list]
49}
50
51main(...process.argv.slice(2));

Callers 1

listImages.jsFile · 0.70

Calls 1

listImagesFunction · 0.85

Tested by

no test coverage detected