Last active
October 18, 2018 13:35
-
-
Save tuor4eg/0203e6a574e32eeecaaebc4b4b13cbcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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