All Products
Search
Document Center

Object Storage Service:Query the region of a bucket (Node.js SDK)

Last Updated:Nov 29, 2025

A bucket is a container that is used to store objects in Object Storage Service (OSS). Every object is contained in a bucket. This topic describes how to query the region of a bucket.

Example code

The following sample code shows how to query the region or location of a bucket:

const OSS = require('ali-oss')

const client = new OSS({
    // Get access credentials from environment variables. Before running this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
    accessKeyId: process.env.OSS_ACCESS_KEY_ID,
    accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
    // Set yourRegion to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
    region: 'oss-cn-hangzhou',
    // Use the V4 signature algorithm.
    authorizationV4: true,
    // Set yourBucketName to the name of the bucket.
    bucket: 'yourBucketName',
    // Set yourEndpoint to the public endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
    endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  });

async function getLocation() {
  try {
    const result = await client.getBucketInfo();
    console.log(result.bucket.Location);
  } catch (e) {
    console.log(e);
  }
}

getLocation();

References