Good morning classmates would like to know how to perform this process, get the data of a MySQL query in a JSON but can obtain it through a URL or in case of tests postman
, the languages that I usually use are Laravel
and I was trying with nodejs
The question I want to ask is
SELECT * FROM usuarios;
In node I have this
var mysql = require("mysql");
//Database connection
app.use(function(req, res, next){
res.locals.connection = mysql.createConnection({
host : '127.0.0.1',
user : 'root',
password : 'SuperSecreto',
database : 'biometricopruebas',
port: '3307'
});
// res.locals.connect();
// next();
});
and this would supposedly get
router.get('/', function(req, res, next) {
res.locals.connection.query('SELECT * from usuarios', function (error, results, fields) {
if (error) throw error;
res.send(JSON.stringify({"status": 200, "error": null, "response": results}));
});
});
I put this because until now it is what I have tried, I do not know if there is another better way to do it, since this small API will be for angular and an android app, I hope I explained it well