|
| 1 | +// Copyright 2019 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +function main(bucketName = 'my-new-bucket') { |
| 18 | + // [START storage_quickstart] |
| 19 | + // Imports the Google Cloud client library |
| 20 | + const {Storage} = require('@google-cloud/storage'); |
| 21 | + |
| 22 | + // For more information on ways to initialize Storage, please see |
| 23 | + // https://googleapis.dev/nodejs/storage/latest/Storage.html |
| 24 | + |
| 25 | + // Creates a client using Application Default Credentials |
| 26 | + const storage = new Storage(); |
| 27 | + |
| 28 | + // Creates a client from a Google service account key |
| 29 | + // const storage = new Storage({keyFilename: 'key.json'}); |
| 30 | + |
| 31 | + /** |
| 32 | + * TODO(developer): Uncomment these variables before running the sample. |
| 33 | + */ |
| 34 | + // The ID of your GCS bucket |
| 35 | + // const bucketName = 'your-unique-bucket-name'; |
| 36 | + |
| 37 | + async function createBucket() { |
| 38 | + try { |
| 39 | + // Creates the new bucket |
| 40 | + await storage.createBucket(bucketName); |
| 41 | + console.log(`Bucket ${bucketName} created.`); |
| 42 | + } catch (error) { |
| 43 | + console.error('Error executing create bucket:', error.message || error); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + createBucket(); |
| 48 | + // [END storage_quickstart] |
| 49 | +} |
| 50 | + |
| 51 | +main(...process.argv.slice(2)); |
0 commit comments