do not understand why add await userInfo.save (); to report Unexpected identifier error, really can not find the problem, ask God for help, thank you!
const config = require (".. / config")
const axios = require ("axios")
const mongoose = require (" mongoose")
const User = mongoose.model ("User")
/ / console.log (" User");
/ / console.log (User);
module.exports = async function (code) {
var url = [
config.wechat,
"?appid=",
config.appId,
"&secret=",
config.appSecret,
"&js_code=",
code,
"&grant_type=authorization_code"
].join("")
axios.get(url)
.then(function(response){
const userInfo = new User({
sessionKey:response.data.session_key,
openid:response.data.openid
})
console.log("userInfo");
console.log(userInfo);
await userInfo.save();
})
.catch(function(error){
console.log(error);
});
}