The `wx-server-sdk` is the official Software Development Kit for interacting with WeChat Mini Program Cloud Development services from within Cloud Functions. It provides a comprehensive set of APIs for accessing cloud resources such as Cloud Database (MongoDB-like), Cloud Storage (object storage), and invoking other Cloud Functions. The SDK is designed to run in a Node.js environment, specifically within the WeChat Cloud Function runtime. The current stable version is 3.0.4, last published approximately two months ago (as of early 2026). While there isn't a strict, publicly defined release cadence, updates are regularly issued to introduce new features, improve performance, and address bugs. Its primary differentiation lies in its deep integration with the WeChat ecosystem, offering seamless backend support for Mini Programs without needing to manage traditional servers.
npm install wx-server-sdkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates initializing the SDK, performing basic database operations (add and query), and invoking another Cloud Function within a WeChat Cloud Function. It highlights best practices for error handling and accessing user context.
Review any code that serializes BigInt values from database queries or other SDK operations to JSON. Adjust parsing logic to handle BigInts as strings or use custom serialization/deserialization logic if numeric representation is strictly required. For example, convert BigInt to `Number()` if within safe integer limits before JSON.stringify.
Implement robust access control policies (ACLs) at the database collection level, use database security rules, and strictly validate all incoming data and user permissions within your Cloud Functions. Never trust client-side input directly.
Navigate to your Cloud Function's directory (e.g., `cloudfunctions/myFunction`) and run `npm install --save wx-server-sdk@latest`. Ensure each function requiring the SDK has its own `node_modules` with the dependency.
Ensure `cloud.init()` is the first cloud-related call in your Cloud Function's `main` entry point, ideally configuring the `env` parameter with your Cloud Development environment ID (e.g., `cloud.init({ env: 'your-env-id' })`).Navigate into the `cloudfunctions/<your-function-name>` directory and run `npm install --save wx-server-sdk`.
Add `cloud.init({ env: 'your-environment-id' });` at the beginning of your Cloud Function's `main` function.Ensure `db.collection('your_collection_name')` passes a non-empty string as the collection identifier.Declare your Cloud Function's entry point `export async function main(event: any, context: any) { ... }`.