- get_version.js
const mysql = require('mysql');
var version = '';
function execute() {
connection.query('SELECT VERSION() as version', function (error, results, fields) {
if (error) throw error;
version = results[0].version;
console.log(version); // 8.0.15
});
}
- routes/index.js
const get_version = require('./get_version')
router.post('/test',function (req, res, next) {
var mysqlVersion = get_version.execute();
**console.log(mysqlVersion);** // output: undefined, i want 8.0.15
});
First of all, this question is similar to other questions,
but it's so hard to understand as other people's questions.
This code cannot be executed.
I know that this problem requires understanding of the callback function.
What is the most similar way to execute the code for this issue, like ruby, php?
This may be a strange question,
but I think there's a way to do it as similarly as possible.
I just want to know the ways of people who know more than I am a beginner.