Environment
tcb.SYMBOL_CURRENT_ENV
Field description: This field is used during initialization to specify the environment for requesting the current cloud function.
Note: Starting from v3, if the
envparameter is not specified during initializationinit({}), the current cloud function environment ID will be used by default instead of the default CloudBase environment. To use the default CloudBase environment, specifyinit({env: tcb.SYMBOL_DEFAULT_ENV}).
Sample code
import tcb from '@cloudbase/node-sdk'
// Initialize using the current cloud function environment
const app = tcb.init({ env: tcb.SYMBOL_CURRENT_ENV })
exports.main = async (event, context) => {
//Business logic.
}
parseContext
1. Interface Description
Function: Parse environment variables in the cloud function environment. (Parameters can be obtained directly from the cloud function's entry parameter context.)
Interface declaration: parseContext(context): Object
2. Response
3. Sample Code
import tcb from '@cloudbase/node-sdk'
exports.main = async (event, context) => {
// The context parameter is taken from the context object of the cloud function's entry function handler
const envObj = tcb.parseContext(context)
// Print cloud function environment variables
console.log(envObj)
}
