Skip to content

Instantly share code, notes, and snippets.

@tuor4eg
Last active October 18, 2018 13:35
Show Gist options
  • Save tuor4eg/0203e6a574e32eeecaaebc4b4b13cbcd to your computer and use it in GitHub Desktop.
Save tuor4eg/0203e6a574e32eeecaaebc4b4b13cbcd to your computer and use it in GitHub Desktop.
const mysql = require('mysql');
const Express = require('express');
const connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '123',
database : 'node_test'
});
const getQuery = async () => {
const general = [];
await connection.connect();
await connection.query('select * from test', (error, results) => {
if (error) throw error;
general.push(JSON.stringify(results));
console.log(general);
return;
});
await connection.end();
return general;
};
const app = new Express;
app.get('/', (req, res) => {
res.send(getQuery());
});
app.listen(3000, () => {
console.log('Example Express app listening on port 3000!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment