SecretID
and SecretKey
. SecretID
is used to identify the API requester, while SecretKey
is a key used for signature string encryption and authentication by the server. You can get them on the API Key Management page as shown below:Note:Your security credential represents your account identity and granted permissions, which is equivalent to your login password. Do not disclose your
SecretKey
to others.
\*.tencentcloudapi.com
and varies by product. For example, the endpoint of CVM is cvm.tencentcloudapi.com
. For specific endpoints, please see the API documentation of the corresponding product.Installation through npm is the recommended way to use the SDK for Node.js. npm is a dependency manager for Node.js that supports the dependencies your project requires and installs them into your project. For more information, please visit npm official website.
npm install tencentcloud-sdk-nodejs --save
Note:
- The above import method downloads the SDKs of all Tencent Cloud products to your local system. You can replace
tencentcloud-sdk-nodejs
with a specific product SDK name such astencentcloud-sdk-nodejs-cvm/cbs/vpc
to import the SDK of the specific product. In the code, you can changerequire("tencentcloud-sdk-nodejs")
torequire("tencentcloud-sdk-nodejs-cvm/cbs/vpc")
and keep the rest unchanged, which can greatly save the storage space. For more information, please see the sample.
const tencentcloud = require("tencentcloud-sdk-nodejs")
// Import the client models of the corresponding product module
const CvmClient = tencentcloud.cvm.v20170312.Client
const clientConfig = {
// Tencent Cloud authentication information
credential: {
secretId: "secretId",
secretKey: "secretKey",
},
// Product region
region: "ap-shanghai",
// Optional instance configuration
profile: {
signMethod: "HmacSHA256", // Signature algorithm
httpProfile: {
reqMethod: "POST", // Request method
reqTimeout: 30, // Request timeout period in seconds, which is 60s by default
},
},
}
// Instantiate the client object of the requested product (with CVM as an example)
const client = new CvmClient(clientConfig)
// Call the API you want to access through the client object; you need to pass in the request object and the response callback function
client.DescribeZones().then(
(data) => {
console.log(data)
},
(err) => {
console.error("error", err)
}
)
Note:During execution, you need to replace
secretId
andsecretKey
with real values.
In projects that support typescript, use the following method to call:
import * as tencentcloud from "tencentcloud-sdk-nodejs"
// Import the client models of the corresponding product module
const CvmClient = tencentcloud.cvm.v20170312.Client
const clientConfig = {
// Tencent Cloud authentication information
credential: {
secretId: "secretId",
secretKey: "secretKey",
},
// Product region
region: "ap-shanghai",
// Optional instance configuration
profile: {
signMethod: "HmacSHA256", // Signature algorithm
httpProfile: {
reqMethod: "POST", // Request method
reqTimeout: 30, // Request timeout period in seconds, which is 60s by default
},
},
}
// Instantiate the client object of the requested product (with CVM as an example)
const client = new CvmClient(clientConfig)
// Call the API you want to access through the client object; you need to pass in the request object and the response callback function
client.DescribeZones().then(
(data) => {
console.log(data)
},
(err) => {
console.error("error", err)
}
)
The input parameters for instantiating Client
support the clientConfig
data structure. For more information, please see ClientConfig.
For more demos, please go to the examples
directory.
If there is a proxy in your environment, you need to set the system environment variable https_proxy
; otherwise, it may not be called normally, and a connection timeout exception will be thrown.
We recommend you use the new version of the SDK for Node.js. If you have to use a legacy SDK, please go to the GitHub repository.
Was this page helpful?