set up a get route express app code example
Example: nodejs express routing get
const express = require('express');
const mysql = require('mysql');
const db = mysql.createConnection({
host: 'localhost',
user: 'yourusername',
password: 'yourpassword'
});
db.connect((error) => {
if(error) {
throw error;
}
console.log('MySQL Connected');
});
const app = express();
app.get('yourroute', (request, response) => {
let sql = 'SELECT * FROM yourtable';
let query = db.query(sql, (error, result) => {
if(error) {
throw error;
}
console.log(result)
})
});
app.listen('3000', () => {
console.log('Server is listening on port 3000');
});