Google Cloud Storage: Node.js Client
Node.js idiomatic client for Cloud Storage.
Cloud Storage allows world-wide storage and retrieval of any amount of data at any time. You can use Google Cloud Storage for a range of scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download.
A comprehensive list of changes in each version may be found in the CHANGELOG.
- Google Cloud Storage Node.js Client API Reference
- Google Cloud Storage Documentation
- github.com/googleapis/nodejs-storage
Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.
Table of contents:
Quickstart
Before you begin
- Select or create a Cloud Platform project.
- Enable billing for your project.
- Enable the Google Cloud Storage API.
- Set up authentication with a service account so you can access the API from your local workstation.
Installing the client library
npm install @google-cloud/storage
Using the client library
// 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);
Samples
Samples are in the samples/
directory. Each sample's README.md
has instructions for running its sample.
Sample | Source Code | Try it |
---|---|---|
Add Bucket Conditional Binding | source code | |
Add Bucket Default Owner Acl | source code | |
Add Bucket Iam Member | source code | |
Storage Add Bucket Label. | source code | |
Add Bucket Owner Acl | source code | |
Bucket Website Configuration. | source code | |
Add File Owner Acl | source code | |
Storage Get Bucket Metadata. | source code | |
Change Bucket's Default Storage Class. | source code | |
Storage File Convert CSEK to CMEK. | source code | |
Storage Combine files. | source code | |
Storage Configure Bucket Cors. | source code | |
Configure Retries | source code | |
Copy File | source code | |
Copy Old Version Of File. | source code | |
Create a Dual-Region Bucket | source code | |
Create Bucket With Storage Class and Location. | source code | |
Create Bucket With Turbo Replication | source code | |
Create New Bucket | source code | |
Create Notification | source code | |
Delete Bucket | source code | |
Delete File | source code | |
Delete Notification | source code | |
Delete Old Version Of File. | source code | |
Disable Bucket Lifecycle Management | source code | |
Storage Disable Bucket Versioning. | source code | |
Disable Default Event Based Hold | source code | |
Disable Requester Pays | source code | |
Disable Uniform Bucket Level Access | source code | |
Download Byte Range | source code | |
Download Encrypted File | source code | |
Download File | source code | |
Download a File in Chunks With Transfer Manager | source code | |
Download File Using Requester Pays | source code | |
Download Folder With Transfer Manager | source code | |
Download Into Memory |