All Products
Search
Document Center

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

Last Updated:Mar 20, 2026

Use the OSS Node.js SDK to get the region where a bucket is located.

Prerequisites

Before you begin, ensure that you have:

  • An OSS bucket

  • The OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables set with valid AccessKey credentials

Get the bucket region

Call getBucketInfo() and read result.bucket.Location from the response. The returned value is the region ID of the bucket, for example, oss-cn-hangzhou.

const OSS = require('ali-oss')

const client = new OSS({
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,       // AccessKey ID
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET, // AccessKey secret
  region: 'oss-cn-hangzhou',         // Region where the bucket is located
  authorizationV4: true,             // Use the V4 signature algorithm
  bucket: 'yourBucketName',          // Name of the bucket
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com', // Public endpoint of the region
});

async function getLocation() {
  try {
    const result = await client.getBucketInfo();
    console.log(result.bucket.Location); // Example output: oss-cn-hangzhou
  } catch (e) {
    console.log(e);
  }
}

getLocation();

Replace the following placeholders with your actual values:

PlaceholderDescriptionExample
yourBucketNameName of the bucketmy-bucket
oss-cn-hangzhouRegion ID where the bucket is locatedoss-cn-hangzhou
https://oss-cn-hangzhou.aliyuncs.comPublic endpoint of the regionhttps://oss-cn-hangzhou.aliyuncs.com

What's next