I am trying to get the return value from a js function in node js and return the value in a post method in my server file. But for some reason, I keep getting undefined. What could I be doing wrong ?My goal is to return the records variable to my server.js file This is what I tried so far:-
sqlconfig.js
var sql = require('mssql');
var config = {
  user: 'realm',
  password: 'friend',
  server: '123.45.67.89\\SQL2014',
  database: 'ArtCaffee'
};
module.exports = {
  sqlconnecttodb: function() {
    sql.connect(config, function(err) {
      if (err) console.log("message is for" + err);
    });
  },
  updateMember: function(Country, BankName, Password, PublicIP, UserID) {
    sql.connect(config, function(err) {
      if (err) console.log("message is for" + err);
      new sql.Request()
        .input('Country', sql.VarChar(50), Country)
        .input('BankName', sql.VarChar(50), BankName)
        .input('Password', sql.VarChar(50), Password)
        .input('PublicIP', sql.VarChar(50), PublicIP)
        .input('UserID', sql.VarChar(50), UserID)
        .execute('p_LoginUser').then(function(result) {
          var records = result[0];
          return records;
        }).catch(function(err) {
          console.dir(err);
        });
    });
  }
};
Server.js
var cnn = require('./sqlconfig.js');
var express = require('express');
var app = express();
const bodyParser = require('body-parser');
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({
  extended: true
}));
app.get('/', function(req, res) {
  res.render('pages/index.ejs');
});
app.post('/', function(req, res) {
  console.log({
    username: req.body.uname
  });
  console.log({
    password: req.body.upass
  });
  var r = cnn.updateMember("Kenya", "Artcaffe Nairobi", "admin1234", "127.0.0.1", "admin2");
  console.log(r); // The value of r is still undefined
});
 
     
    