All Products
Search
Document Center

Object Storage Service:Get bucket information (Node.js SDK)

Last Updated:Mar 20, 2026

Use getBucketInfo to retrieve metadata about an Object Storage Service (OSS) bucket, including its region, storage class, versioning state, creation date, and owner details.

Prerequisites

Before you begin, make sure you have:

  • An OSS bucket

  • The OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables set with valid access key credentials

Get bucket information

The following example calls getBucketInfo and reads the returned fields from the response object.

const OSS = require('ali-oss');
// import OSS from 'ali-oss'; // ESM import

const client = new OSS({
  region: '<your-region>',           // required — for example, oss-cn-hangzhou
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,      // required
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET, // required
  authorizationV4: true,
  bucket: '<your-bucket-name>',      // required
});

async function getBucketInfo() {
  const result = await client.getBucketInfo('<your-bucket-name>');
  // result.bucket = {
  //   Location: 'oss-cn-hangzhou',   // region where the bucket is located
  //   Name: 'examplebucket',          // bucket name
  //   Owner: {
  //     ID: '...',                    // owner account ID
  //     DisplayName: '...',           // same as owner ID
  //   },
  //   CreationDate: '...',            // bucket creation date
  //   StorageClass: 'Standard',       // storage class
  //   Versioning: '',                 // versioning state
  // }

  console.log(result.bucket.Location);
  console.log(result.bucket.Name);
  console.log(result.bucket.Owner.ID);
  console.log(result.bucket.Owner.DisplayName);
  console.log(result.bucket.CreationDate);
  console.log(result.bucket.StorageClass);
  console.log(result.bucket.Versioning);
}

getBucketInfo();

Replace the following placeholders with actual values:

PlaceholderDescriptionExample
<your-region>Region where the bucket is locatedoss-cn-hangzhou
<your-bucket-name>Name of your bucketexamplebucket

References