Google Cloud Storage: Node.js Client
Node.js idiomatic client forCloud Storage.
Cloud Storage allows world-widestorage and retrieval of any amount of data at any time. You can use GoogleCloud Storage for a range of scenarios including serving website content,storing data for archival and disaster recovery, or distributing large dataobjects to users via direct download.
A comprehensive list of changes in each version may be found inthe 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 olderGoogle APIs Client Libraries, inClient 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 so you can access theAPI from your local workstation.
Installing the client library
npm install @google-cloud/storageUsing the client library
// Imports the Google Cloud client libraryconst {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 Credentialsconst 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 thesamples/ directory. Each sample'sREADME.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 a hierarchical namespace enabled bucket | source code | ![]() |
| Create a Bucket with object retention enabled. | 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 | source code | ![]() |
| Download Many Files With Transfer Manager | source code | ![]() |
| Storage Download Public File. | source code | ![]() |
| Enable Bucket Lifecycle Management | source code | ![]() |
| Storage Enable Bucket Versioning. | source code | ![]() |
| Enable Default Event Based Hold | source code | ![]() |
| Enable Default KMS Key | source code | ![]() |
| Enable Requester Pays | source code | ![]() |
| Enable Uniform Bucket Level Access | source code | ![]() |
| Change File's Storage Class. | source code | ![]() |
| Storage Set File Metadata. | source code | ![]() |
| Generate Encryption Key | source code | ![]() |
| Generate Signed Url | source code | ![]() |
| Generate V4 Read Signed Url | source code | ![]() |
| Generate V4 Signed Policy | source code | ![]() |
| Generate V4 Upload Signed Url | source code | ![]() |
| Get Autoclass | source code | ![]() |
| Get Default Event Based Hold | source code | ![]() |
| Get Metadata | source code | ![]() |
| Get Metadata Notifications | source code | ![]() |
| Get Public Access Prevention | source code | ![]() |
| Get RPO | source code | ![]() |
| Get Requester Pays Status | source code | ![]() |
| Get Retention Policy | source code | ![]() |
| Storage Get Service Account. | source code | ![]() |
| Get Soft Deleted Bucket | source code | ![]() |
| Get Uniform Bucket Level Access | source code | ![]() |
| Activate HMAC SA Key. | source code | ![]() |
| Create HMAC SA Key. | source code | ![]() |
| Deactivate HMAC SA Key. | source code | ![]() |
| Delete HMAC SA Key. | source code | ![]() |
| Get HMAC SA Key Metadata. | source code | ![]() |
| List HMAC SA Keys Metadata. | source code | ![]() |
| List Buckets | source code | ![]() |
| List Files | source code | ![]() |
| List Files By Prefix | source code | ![]() |
| List Files Paginate | source code | ![]() |
| List Files with Old Versions. | source code | ![]() |
| List Notifications | source code | ![]() |
| List Soft Deleted Bucket | source code | ![]() |
| Lock Retention Policy | source code | ![]() |
| Storage Make Bucket Public. | source code | ![]() |
| Make Public | source code | ![]() |
| Move File | source code | ![]() |
| Move File Atomic | source code | ![]() |
| Print Bucket Acl | source code | ![]() |
| Print Bucket Acl For User | source code | ![]() |
| Print File Acl | source code | ![]() |
| Print File Acl For User | source code | ![]() |
| Quickstart | source code | ![]() |
| Release Event Based Hold | source code | ![]() |
| Release Temporary Hold | source code | ![]() |
| Remove Bucket Conditional Binding | source code | ![]() |
| Storage Remove Bucket Cors Configuration. | source code | ![]() |
| Remove Bucket Default Owner | source code | ![]() |
| Remove Bucket Iam Member | source code | ![]() |
| Storage Remove Bucket Label. | source code | ![]() |
| Remove Bucket Owner Acl | source code | ![]() |
| Remove Default KMS Key. | source code | ![]() |
| Remove File Owner Acl | source code | ![]() |
| Remove Retention Policy | source code | ![]() |
| Rename File | source code | ![]() |
| Restore Soft Deleted Bucket | source code | ![]() |
| Rotate Encryption Key | source code | ![]() |
| Set Autoclass | source code | ![]() |
| Set Client Endpoint | source code | ![]() |
| Set Event Based Hold | source code | ![]() |
| Set the object retention policy of a File. | source code | ![]() |
| Set Public Access Prevention Enforced | source code | ![]() |
| Set Public Access Prevention Inherited | source code | ![]() |
| Set RPO Async Turbo | source code | ![]() |
| Set RPO Default | source code | ![]() |
| Set Retention Policy | source code | ![]() |
| Set Temporary Hold | source code | ![]() |
| Stream File Download | source code | ![]() |
| Stream File Upload | source code | ![]() |
| Upload a directory to a bucket. | source code | ![]() |
| Upload Directory With Transfer Manager | source code | ![]() |
| Upload Encrypted File | source code | ![]() |
| Upload File | source code | ![]() |
| Upload a File in Chunks With Transfer Manager | source code | ![]() |
| Upload File With Kms Key | source code | ![]() |
| Upload From Memory | source code | ![]() |
| Upload Many Files With Transfer Manager | source code | ![]() |
| Upload Without Authentication | source code | ![]() |
| Upload Without Authentication Signed Url | source code | ![]() |
| View Bucket Iam Members | source code | ![]() |
TheGoogle Cloud Storage Node.js Client API Reference documentationalso contains samples.
Supported Node.js Versions
Our client libraries follow theNode.js release schedule.Libraries are compatible with all currentactive andmaintenance versions ofNode.js.If you are using an end-of-life version of Node.js, we recommend that you updateas soon as possible to an actively supported LTS version.
Google's client libraries support legacy versions of Node.js runtimes on abest-efforts basis with the following warnings:
- Legacy versions are not tested in continuous integration.
- Some security patches and features cannot be backported.
- Dependencies cannot be kept up-to-date.
Client libraries targeting some end-of-life versions of Node.js are available, andcan be installed through npmdist-tags.The dist-tags follow the naming conventionlegacy-(version).For example,npm install @google-cloud/storage@legacy-8 installs client librariesfor versions compatible with Node.js 8.
Versioning
This library followsSemantic Versioning.
This library is considered to bestable. The code surface will not change in backwards-incompatible waysunless absolutely necessary (e.g. because of critical security issues) or withan extensive deprecation period. Issues and requests againststable librariesare addressed with the highest priority.
More Information:Google Cloud Platform Launch Stages
Contributing
Contributions welcome! See theContributing Guide.
Please note that thisREADME.md, thesamples/README.md,and a variety of configuration files in this repository (including.nycrc andtsconfig.json)are generated from a central template. To edit one of these files, make an editto its templates indirectory.
License
Apache Version 2.0
SeeLICENSE
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-30 UTC.
