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
aws-sdk
The aws-sdk package is a client library for Amazon Web Services (AWS), including Amazon S3, which is a similar object storage service to Google Cloud Storage. It provides a wide range of functionalities to interact with various AWS services.
azure-storage
The azure-storage package is a client library for Microsoft Azure Storage. Like Google Cloud Storage, Azure Storage offers blob storage for unstructured data, and this package allows Node.js developers to work with Azure blobs, files, queues, and tables.
pkgcloud
The pkgcloud package is a multi-cloud provisioning library for Node.js that abstracts away differences among multiple cloud providers. It supports various cloud services, including storage services like Amazon S3 and Rackspace Cloud Files, and can be used as an alternative to provider-specific packages like @google-cloud/storage.
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.
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
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
async function createBucket() {
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.
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.
If you are using an end-of-life version of Node.js, we recommend that you update
as soon as possible to an actively supported LTS version.
Google's client libraries support legacy versions of Node.js runtimes on a
best-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, and
can be installed through npm dist-tags.
The dist-tags follow the naming convention legacy-(version)
.
For example, npm install @google-cloud/storage@legacy-8
installs client libraries
for versions compatible with Node.js 8.
Versioning
This library follows Semantic Versioning.
This library is considered to be 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 stable 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 templates in
directory.
License
Apache Version 2.0
See LICENSE