1
I have a JS application that runs via browser console. I would like to know the possibilities of sending and receiving data via mysql via the Console.
I don’t know if it’s possible either.
I tried something, but it didn’t work. Example:
lastMsg = "Message received"; // recebe a msg
var mysql = require('mysql'); //
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO mensagens (textomsg) VALUES (lastMsg)";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
I get the following error on the console
Uncaught Referenceerror: require is not defined
Browser console + mysql will not work, you can use localStorage if you want to run in the browser or an api for the server.
– Denis Rudnei de Souza
Which path to an API?
– Expl0it
I don’t understand the question
– Denis Rudnei de Souza
What is the best way to make an API in this case per console
– Expl0it
You do not make an API in the browser console, it will be a server that provides the information, hence through the interface you can make the requests for the API, anyway, there is no single/simple way to do this.
– Denis Rudnei de Souza