I'm working on a food ordering app in flutter and the API in Express.js with MySql for the database. I was able to connect to the database and receive the JSON data and console.log() them, but I don't know how to send them to the app. Any help would be highly appreciated.
Here's the code.
const express = require('express');
const router = express.Router();
const mysql = require('mysql');
var pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: '',
database: 'ala_ainy_db',
connectionLimit: 10,
});
router.get('/', (req, res, next) => {
pool.getConnection(function (err, conn) {
if (err) return;
conn.query('SELECT * FROM restaurants', function (err, rows) {
if (err) {
conn.release();
console.log('failed');
}
rows.forEach((row) => {
console.log(`ID: ${row.id}, Name: ${row.name}`);
});
conn.release();
})
});
});