个人案例
- 民宿多多
让住房更简单
名宿多多扫码体验
只有一个文件有package.json
Cannot find module 'wx-server-sdk简单尝试下云函数 [代码]'use strict'[代码][代码];[代码][代码]const cloud = require([代码][代码]'wx-server-sdk'[代码][代码]);[代码][代码]cloud.init({[代码][代码] [代码][代码]env: [代码][代码]'demo'[代码][代码]});[代码][代码]exports.main = (event, context, callback) => {[代码] [代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]db.collection([代码][代码]'user'[代码][代码]).add({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]username: [代码][代码]"learn cloud database"[代码][代码],[代码][代码] [代码][代码]password: [代码][代码]"www"[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](e) {[代码][代码] [代码][代码]console.error(e)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]var[代码] [代码]num1 = parseInt(event.a);[代码][代码] [代码][代码]var[代码] [代码]num2 = parseInt(event.b);[代码][代码] [代码][代码]var[代码] [代码]result=num1+num2;[代码][代码] [代码][代码]event.sum=result;[代码][代码] [代码][代码]console.log([代码][代码]"key:"[代码] [代码]+ event.a);[代码][代码] [代码][代码]console.log([代码][代码]"Hello World"[代码][代码])[代码][代码] [代码][代码]console.log(event)[代码][代码] [代码][代码]console.log(event[[代码][代码]"non-exist"[代码][代码]])[代码][代码] [代码][代码]console.log(context);[代码][代码] [代码][代码]event.msg=[代码][代码]"hello"[代码][代码];[代码][代码] [代码][代码]callback([代码][代码]null[代码][代码], event);[代码][代码]};[代码] 运行的时候出现 返回结果: {"errorCode":10004,"errorMessage":"user code exception caught","stackTrace":"Cannot find module 'wx-server-sdk'"}
2018-09-11