1
I have learned how to fetch information from Mysql database, but I cannot manipulate this data to expose in HTML pages. The code I’m going to expose underneath I got from w3school:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM customers", function (err, result, fields) {
if (err) throw err;
console.log(result);
});
});
Pay attention to the part where I take the data, it is stored in the result variable, only you can not manipulate this information outside the scope of the function. How do I take this data and place the result on an HTML page? Is it possible to do this without a framework? If not, which framework to use?
You can do it by hand with http modules or use express (which is what most do)
– Costamilam
When I extract the information, it gets stuck in the context of the function. How do I export this data to other modules?
– João Victor Nóbrega
You need to create and export a function that executes the query and returns the result. Give a look in that question I think it’ll help you
– Costamilam