Google Cloud Storage: Node.js Client

release levelnpm version

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.

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

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Google Cloud Storage API.
  4. Set up authentication so you can access theAPI from your local workstation.

Installing the client library

npm install @google-cloud/storage

Using 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.

SampleSource CodeTry it
Add Bucket Conditional Bindingsource codeOpen in Cloud Shell
Add Bucket Default Owner Aclsource codeOpen in Cloud Shell
Add Bucket Iam Membersource codeOpen in Cloud Shell
Storage Add Bucket Label.source codeOpen in Cloud Shell
Add Bucket Owner Aclsource codeOpen in Cloud Shell
Bucket Website Configuration.source codeOpen in Cloud Shell
Add File Owner Aclsource codeOpen in Cloud Shell
Storage Get Bucket Metadata.source codeOpen in Cloud Shell
Change Bucket's Default Storage Class.source codeOpen in Cloud Shell
Storage File Convert CSEK to CMEK.source codeOpen in Cloud Shell
Storage Combine files.source codeOpen in Cloud Shell
Storage Configure Bucket Cors.source codeOpen in Cloud Shell
Configure Retriessource codeOpen in Cloud Shell
Copy Filesource codeOpen in Cloud Shell
Copy Old Version Of File.source codeOpen in Cloud Shell
Create a Dual-Region Bucketsource codeOpen in Cloud Shell
Create a hierarchical namespace enabled bucketsource codeOpen in Cloud Shell
Create a Bucket with object retention enabled.source codeOpen in Cloud Shell
Create Bucket With Storage Class and Location.source codeOpen in Cloud Shell
Create Bucket With Turbo Replicationsource codeOpen in Cloud Shell
Create New Bucketsource codeOpen in Cloud Shell
Create Notificationsource codeOpen in Cloud Shell
Delete Bucketsource codeOpen in Cloud Shell
Delete Filesource codeOpen in Cloud Shell
Delete Notificationsource codeOpen in Cloud Shell
Delete Old Version Of File.source codeOpen in Cloud Shell
Disable Bucket Lifecycle Managementsource codeOpen in Cloud Shell
Storage Disable Bucket Versioning.source codeOpen in Cloud Shell
Disable Default Event Based Holdsource codeOpen in Cloud Shell
Disable Requester Payssource codeOpen in Cloud Shell
Disable Uniform Bucket Level Accesssource codeOpen in Cloud Shell
Download Byte Rangesource codeOpen in Cloud Shell
Download Encrypted Filesource codeOpen in Cloud Shell
Download Filesource codeOpen in Cloud Shell
Download a File in Chunks With Transfer Managersource codeOpen in Cloud Shell
Download File Using Requester Payssource codeOpen in Cloud Shell
Download Folder With Transfer Managersource codeOpen in Cloud Shell
Download Into Memorysource codeOpen in Cloud Shell
Download Many Files With Transfer Managersource codeOpen in Cloud Shell
Storage Download Public File.source codeOpen in Cloud Shell
Enable Bucket Lifecycle Managementsource codeOpen in Cloud Shell
Storage Enable Bucket Versioning.source codeOpen in Cloud Shell
Enable Default Event Based Holdsource codeOpen in Cloud Shell
Enable Default KMS Keysource codeOpen in Cloud Shell
Enable Requester Payssource codeOpen in Cloud Shell
Enable Uniform Bucket Level Accesssource codeOpen in Cloud Shell
Change File's Storage Class.source codeOpen in Cloud Shell
Storage Set File Metadata.source codeOpen in Cloud Shell
Generate Encryption Keysource codeOpen in Cloud Shell
Generate Signed Urlsource codeOpen in Cloud Shell
Generate V4 Read Signed Urlsource codeOpen in Cloud Shell
Generate V4 Signed Policysource codeOpen in Cloud Shell
Generate V4 Upload Signed Urlsource codeOpen in Cloud Shell
Get Autoclasssource codeOpen in Cloud Shell
Get Default Event Based Holdsource codeOpen in Cloud Shell
Get Metadatasource codeOpen in Cloud Shell
Get Metadata Notificationssource codeOpen in Cloud Shell
Get Public Access Preventionsource codeOpen in Cloud Shell
Get RPOsource codeOpen in Cloud Shell
Get Requester Pays Statussource codeOpen in Cloud Shell
Get Retention Policysource codeOpen in Cloud Shell
Storage Get Service Account.source codeOpen in Cloud Shell
Get Soft Deleted Bucketsource codeOpen in Cloud Shell
Get Uniform Bucket Level Accesssource codeOpen in Cloud Shell
Activate HMAC SA Key.source codeOpen in Cloud Shell
Create HMAC SA Key.source codeOpen in Cloud Shell
Deactivate HMAC SA Key.source codeOpen in Cloud Shell
Delete HMAC SA Key.source codeOpen in Cloud Shell
Get HMAC SA Key Metadata.source codeOpen in Cloud Shell
List HMAC SA Keys Metadata.source codeOpen in Cloud Shell
List Bucketssource codeOpen in Cloud Shell
List Filessource codeOpen in Cloud Shell
List Files By Prefixsource codeOpen in Cloud Shell
List Files Paginatesource codeOpen in Cloud Shell
List Files with Old Versions.source codeOpen in Cloud Shell
List Notificationssource codeOpen in Cloud Shell
List Soft Deleted Bucketsource codeOpen in Cloud Shell
Lock Retention Policysource codeOpen in Cloud Shell
Storage Make Bucket Public.source codeOpen in Cloud Shell
Make Publicsource codeOpen in Cloud Shell
Move Filesource codeOpen in Cloud Shell
Move File Atomicsource codeOpen in Cloud Shell
Print Bucket Aclsource codeOpen in Cloud Shell
Print Bucket Acl For Usersource codeOpen in Cloud Shell
Print File Aclsource codeOpen in Cloud Shell
Print File Acl For Usersource codeOpen in Cloud Shell
Quickstartsource codeOpen in Cloud Shell
Release Event Based Holdsource codeOpen in Cloud Shell
Release Temporary Holdsource codeOpen in Cloud Shell
Remove Bucket Conditional Bindingsource codeOpen in Cloud Shell
Storage Remove Bucket Cors Configuration.source codeOpen in Cloud Shell
Remove Bucket Default Ownersource codeOpen in Cloud Shell
Remove Bucket Iam Membersource codeOpen in Cloud Shell
Storage Remove Bucket Label.source codeOpen in Cloud Shell
Remove Bucket Owner Aclsource codeOpen in Cloud Shell
Remove Default KMS Key.source codeOpen in Cloud Shell
Remove File Owner Aclsource codeOpen in Cloud Shell
Remove Retention Policysource codeOpen in Cloud Shell
Rename Filesource codeOpen in Cloud Shell
Restore Soft Deleted Bucketsource codeOpen in Cloud Shell
Rotate Encryption Keysource codeOpen in Cloud Shell
Set Autoclasssource codeOpen in Cloud Shell
Set Client Endpointsource codeOpen in Cloud Shell
Set Event Based Holdsource codeOpen in Cloud Shell
Set the object retention policy of a File.source codeOpen in Cloud Shell
Set Public Access Prevention Enforcedsource codeOpen in Cloud Shell
Set Public Access Prevention Inheritedsource codeOpen in Cloud Shell
Set RPO Async Turbosource codeOpen in Cloud Shell
Set RPO Defaultsource codeOpen in Cloud Shell
Set Retention Policysource codeOpen in Cloud Shell
Set Temporary Holdsource codeOpen in Cloud Shell
Stream File Downloadsource codeOpen in Cloud Shell
Stream File Uploadsource codeOpen in Cloud Shell
Upload a directory to a bucket.source codeOpen in Cloud Shell
Upload Directory With Transfer Managersource codeOpen in Cloud Shell
Upload Encrypted Filesource codeOpen in Cloud Shell
Upload Filesource codeOpen in Cloud Shell
Upload a File in Chunks With Transfer Managersource codeOpen in Cloud Shell
Upload File With Kms Keysource codeOpen in Cloud Shell
Upload From Memorysource codeOpen in Cloud Shell
Upload Many Files With Transfer Managersource codeOpen in Cloud Shell
Upload Without Authenticationsource codeOpen in Cloud Shell
Upload Without Authentication Signed Urlsource codeOpen in Cloud Shell
View Bucket Iam Memberssource codeOpen in Cloud Shell

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.