# init
Before calling the Cloud Base APIs, you need to call the initialization method init
once (globally only once)
The init
method is defined as below:
function init(options): void
The init
method accepts an optional options
parameter, and such a method has no return value.
The options
parameter defines the default settings for Cloud Base, which are used as the default settings for all other cloud APIs called later on. The optional settings provided by options
are as follows:
Field | Data Type | Required | Default | Description |
---|---|---|---|---|
env | string | object | No | default | The default environment settings. The environment ID in the form of an incoming string can be used to specify the default environment for all services, while the incoming object can be used to specify the default environment for each specific service. Refer to the detailed definition below. |
When the incoming env
parameter is an object, it can be used to specify the default environment for each service. The optional fields are as below:
Field | Data Type | Required | Default | Description |
---|---|---|---|---|
database | string | No | default | The default environment settings of database API |
storage | string | No | default | The default environment settings of storage API |
functions | string | No | default | The default environment settings of cloud function API |
Sample code:
const cloud = require('wx-server-sdk')
cloud.init({
env: 'test-x1dzi'
})
Please note that wx-server-sdk
is no longer compatible with the callback of success
, fail
, and complete
, and only Promise
is returned.