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

Function main

storage/createNotification.js:26–62  ·  view source on GitHub ↗
(
  bucketName = 'my-bucket',
  topic = `nodejs-storage-samples-${uuid.v4()}`
)

Source from the content-addressed store, hash-verified

24const uuid = require('uuid');
25
26function main(
27 bucketName = 'my-bucket',
28 topic = `nodejs-storage-samples-${uuid.v4()}`
29) {
30 // [START storage_create_bucket_notifications]
31 /**
32 * TODO(developer): Uncomment the following lines before running the sample.
33 */
34 // The ID of your GCS bucket
35 // const bucketName = 'your-unique-bucket-name';
36
37 // The name of a topic
38 // const topic = 'my-topic';
39
40 // Imports the Google Cloud client library
41 const {Storage} = require('@google-cloud/storage');
42
43 // Creates a client
44 const storage = new Storage();
45
46 async function createNotification() {
47 try {
48 // Creates a notification
49 await storage.bucket(bucketName).createNotification(topic);
50
51 console.log('Notification subscription created.');
52 } catch (error) {
53 console.error(
54 'Error executing create notification:',
55 error.message || error
56 );
57 }
58 }
59
60 createNotification();
61 // [END storage_create_bucket_notifications]
62}
63main(...process.argv.slice(2));

Callers 1

Calls 1

createNotificationFunction · 0.85

Tested by

no test coverage detected