title: Return mysql query to nodejs flash message
body: <p>I am looking to query the tracking numbers by office number.  Then pass the tracking numbers to the req.flash  in the post.  I am able to get the data to log to the console, I am having issues returning it to my main node program so I can use that data in the req.flash message.  How do I get the query results to the main javascript program so I can flash the results of the query in req.flash?</p>
  
  <p>I've tried a few different calls.</p>
  
  <p>Here is my output from the console</p>
  
  <pre><code>[nodemon] starting `node src/server.js`
  body-parser deprecated undefined extended: provide extended option src\server.js:20:14
  App running at http://localhost:3000
  Sanitized: { officeNumber: '1212' }
  the output is 0
  result from db is :  12121212121212
  result from db is :  124563356743435
  result from db is :  354466436646464
  result from db is :  363548367868575
  </code></pre>
  
  <hr>
  
  <p>routes.js</p>
  
  <pre><code>const express = require('express')
  const router = express.Router()
  const { check, validationResult } = require('express-validator/check')
  const { matchedData } = require('express-validator/filter')
  var mysql   = require('mysql'),
      config  = require("./config");
  
      var con = mysql.createConnection(config.db);
  
  
  
  router.post('/trackingnumbers', [
    check('officeNumber')
      .isLength({ min:4, max:4  })
      .withMessage('That office Number doesn‘t look right')
      .trim()
  ], (req, res) =&gt; {
    const errors = validationResult(req)
    if (!errors.isEmpty()) {
      return res.render('trackingnumbers', {
        data: req.body,
        errors: errors.mapped()
      })
    }
  
    const data = matchedData(req)
    console.log('Sanitized:', data)
  var mysql_query3 = require('./mysql_query.js');
  //////////////////////////////////////////////////////////
  output = "0";
  
  
  
  function getTrackingNumbers(officeN, callback)
  {
      con.query('SELECT * from trackingnumbers where office_Number = ' + officeN, function(err, result)
      {
          if (err) 
              callback(err,null);
          else
              //console.log(result);   
  
              for (var i = 0; i &lt; result.length; i++) {
                //  console.log(result[i]);
                  //callback(null,result[i]);
                  callback(null,result[i].tracking_Number);
              }
  
      });
  
  }
  
  
  //call Fn for db query with callback
   getTrackingNumbers(req.body["officeNumber"], function(err,data1){
          if (err) {
              // error handling code goes here
              console.log("ERROR : ",err);            
          } else {            
              // code to execute on data retrieval
              console.log("result from db is : ",data1);
              return data1;
          }    
  
  });
  /////////////////////////////////////////////////////////////////////////////
  console.log("the output is " +  output);
    req.flash('success', 'Thanks your super cool has been inputted' + output)
    //can do 2 flashes here if need to
  
    res.redirect('trackingnumbers')
  })
  
  
  
  
  
  module.exports = router
  </code></pre>