1👍
✅
The answer after hours of toiling is to standup another package that runs node server separately using Express as a router ending up with something like this:
const express = require('express');
const mysqlssh = require('mysql-ssh');
const router = express.Router();
var output;
// Get App User
router.get('/user', (req, res) => {
var query = "SELECT * FROM APPUSERS WHERE EMAIL = 'sample@email.com';";
var result = connectAndQuery(query);
setTimeout(function(){
res.send(output);
}, 3000);
});
function connectAndQuery(command) {
mysqlssh.connect(
{
host: 'address',
user: 'root',
password: 'pwd'
},
{
host: 'localhost',
user: 'root',
password: 'pwd',
database: 'db-name'
}
)
.then(client => {
client.query(command, function (err, results) {//command is query
if (err) throw err;//throws error if anything in the connection goes wrong
output = JSON.stringify(results);
mysqlssh.close();//close sql ssh
return output;
})
})
.catch(err => {
console.log(err)
})
}
module.exports = router;
Source:stackexchange.com