The @google-cloud/storage
package has a single named export which is the
Storage (ES6) class, which should be instantiated with new
.
See Storage and ClientConfig for client methods and configuration options.
Examples
Install the client library with <a href="https://www.npmjs.com/">npm</a>:
```
npm install --save @google-cloud/storage
```
Import the client library
```
const {Storage} = require('@google-cloud/storage');
```
Create a client that uses <a
href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
Default Credentials (ADC)</a>:
```
const storage = new Storage();
```
Create a client with <a
href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
credentials</a>:
```
const storage = new Storage({ projectId:
'your-project-id', keyFilename: '/path/to/keyfile.json'
});
```
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
// For more information on ways to initialize Storage, please see
// https://googleapis.dev/nodejs/storage/latest/Storage.html
// Creates a client using Application Default Credentials
const storage = new Storage();
// Creates a client from a Google service account key
// const storage = new Storage({keyFilename: 'key.json'});
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';
async function createBucket() {
// Creates the new bucket
await storage.createBucket(bucketName);
console.log(`Bucket ${bucketName} created.`);
}
createBucket().catch(console.error);