storage.js
const storage = {
users: {},
addOrUpdateUser: function(user) {
this.users[user.id] = user
},
getUserById: function(id) {
if(this.users[id]) return this.users[id]
return null //или [], смотря как у вас принято
}
}
module.exports = storage
В вашем файле:
var mysql = require('mysql');
const storage = require('./storage')
var conn = mysql.createConnection({
database: '',
host: "",
user: "",
password: ""
});
conn.connect(function(err) {
if (err) throw err;
});
conn.query("SELECT username, id FROM Users WHERE id ="+id,
function(err, results, fields) {
console.log(err);
console.log(results[0].username);
storage.addOrUpdateUser(results[0])
console.log(storage.getUserById(results[0].id))
});