The mysql operation in node has encountered problems that cannot be solved. Great gods are seeking solutions! !

  node.js, question
var mysql=require('mysql');
 var querystring=require('querystring');
 
 
 
 var connection=mysql.createConnection({
 host:'localhost',
 user:'root',
 password:'123456',
 port:'3306',
 database:'wxData',
 
 
 });
 connection.connect(function (err) {
 if (err) {
 Log ('connecnerror:' plus err.message);
 bracket
 return;
 });
 function insertdata(token) {
 var slect ='select * from token';
 var update='UPDATE token SET access_token=?   WHERE id=1';
 var insertString='INSERT INTO token (id, access_token) VALUES (0,?  )' ;
 var value=[token];
 //select mysql
 connection.query(slect,function (err,result) {
 if (result) {
 // update mysql
 connection.query(update,value,function (err,result) {
 console.log(result)
 });
 }else{
 //insert mysql
 connection.query(insertString,value,function (err,result) {
 Log ('insertresult:' plus result');
 });
 bracket
 });
 connection.end();
 bracket
 module.exports.insertdata=insertdata;
 When my database inside has data and can be queried, why can't I perform the next update operation and the output result is always undefined?  Ask for an answer!  !  !

Your code is incomplete, but it can be seen from it that you do not know much about the asynchronous call of JS. This asynchronous call exists in the form of callback function, and your normal call to insertdata is called after connect succeeds, that is, within connect’s callback function. You didn’t do this here, of course, maybe you have any special treatment for the function outside, this is not seen now, so it is difficult to say.