Socket
Socket
Sign inDemoInstall

@google-cloud/storage

Package Overview
Dependencies
22
Maintainers
1
Versions
179
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/storage


Version published
Weekly downloads
3.3M
decreased by-0.06%
Maintainers
1
Created
Weekly downloads
 

Package description

What is @google-cloud/storage?

The @google-cloud/storage npm package is a client library for using Google Cloud Storage, which is a service for storing and accessing data on Google's infrastructure. The package allows Node.js developers to interact with Google Cloud Storage in a server-side application.

What are @google-cloud/storage's main functionalities?

Uploading files

This feature allows users to upload files to a Google Cloud Storage bucket. The code sample demonstrates how to upload a local file to a specified bucket.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function uploadFile() {
  await storage.bucket('my-bucket').upload('local-file-path', {
    destination: 'destination-file-path',
  });
  console.log('File uploaded.');
}
uploadFile().catch(console.error);

Downloading files

This feature enables users to download files from a Google Cloud Storage bucket. The code sample shows how to download a file from a bucket to the local file system.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function downloadFile() {
  const options = {
    destination: 'local-file-path',
  };
  await storage.bucket('my-bucket').file('remote-file-path').download(options);
  console.log('File downloaded.');
}
downloadFile().catch(console.error);

Listing files

This feature provides the ability to list all files in a Google Cloud Storage bucket. The code sample lists the names of all files in a specified bucket.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function listFiles() {
  const [files] = await storage.bucket('my-bucket').getFiles();
  files.forEach(file => console.log(file.name));
}
listFiles().catch(console.error);

Deleting files

This feature allows users to delete files from a Google Cloud Storage bucket. The code sample demonstrates how to delete a specific file from a bucket.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function deleteFile() {
  await storage.bucket('my-bucket').file('file-to-delete').delete();
  console.log('File deleted.');
}
deleteFile().catch(console.error);

Managing buckets

This feature enables users to manage buckets, including creating and deleting buckets. The code sample shows how to create a new bucket in Google Cloud Storage.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function createBucket() {
  await storage.createBucket('new-bucket');
  console.log('Bucket created.');
}
createBucket().catch(console.error);

Other packages similar to @google-cloud/storage

Readme

Source

Google Cloud Platform logo

Google Cloud Storage: Node.js Client

release level npm version codecov

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.

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

  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 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');

// Creates a client
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.
 */
// const bucketName = '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. The samples' README.md has instructions for running the samples.

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
Add Bucket Owner Aclsource codeOpen in Cloud Shell
Add File Owner Aclsource codeOpen in Cloud Shell
Storage Get Bucket Metadata.source codeOpen in Cloud Shell
Copy Filesource 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
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 Encrypted Filesource codeOpen in Cloud Shell
Download Filesource codeOpen in Cloud Shell
Download File Using Requester Payssource 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
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 Upload Signed Urlsource 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 Requester Pays Statussource codeOpen in Cloud Shell
Get Retention Policysource 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 Notificationssource codeOpen in Cloud Shell
Lock Retention Policysource codeOpen in Cloud Shell
Make Publicsource codeOpen in Cloud Shell
Move Filesource codeOpen in Cloud Shell
Notificationssource 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
Remove Bucket Default Ownersource codeOpen in Cloud Shell
Remove Bucket Iam Membersource codeOpen in Cloud Shell
Remove Bucket Owner Aclsource codeOpen in Cloud Shell
Remove File Owner Aclsource codeOpen in Cloud Shell
Remove Retention Policysource codeOpen in Cloud Shell
Rotate Encryption Keysource codeOpen in Cloud Shell
Set Event Based Holdsource codeOpen in Cloud Shell
Set Retention Policysource codeOpen in Cloud Shell
Set Temporaryd Holdsource codeOpen in Cloud Shell
Upload a directory to a bucket.source codeOpen in Cloud Shell
Upload Encrypted Filesource codeOpen in Cloud Shell
Upload Filesource codeOpen in Cloud Shell
Upload File With Kms Keysource codeOpen in Cloud Shell
View Bucket Iam Memberssource codeOpen in Cloud Shell

The Google Cloud Storage Node.js Client API Reference documentation also contains samples.

Supported Node.js Versions

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js.

Client libraries targetting some end-of-life versions of Node.js are available, and can be installed via npm dist-tags. The dist-tags follow the naming convention legacy-(version).

Legacy Node.js versions are supported as a best effort:

  • Legacy versions will not be tested in continuous integration.
  • Some security patches may not be able to be backported.
  • Dependencies will not be kept up-to-date, and features will not be backported.
Legacy tags available
  • legacy-8: install client libraries from this dist-tag for versions compatible with Node.js 8.

Versioning

This library follows Semantic Versioning.

This library is considered to be General Availability (GA). This means it is stable; the code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against GA libraries are addressed with the highest priority.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

Please note that this README.md, the samples/README.md, and a variety of configuration files in this repository (including .nycrc and tsconfig.json) are generated from a central template. To edit one of these files, make an edit to its template in this directory.

License

Apache Version 2.0

See LICENSE

Keywords

FAQs

Last updated on 20 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc