(
bucketName = 'my-bucket',
topic = `nodejs-storage-samples-${uuid.v4()}`
)
| 24 | const uuid = require('uuid'); |
| 25 | |
| 26 | function 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 | } |
| 63 | main(...process.argv.slice(2)); |
no test coverage detected