Connect to the database via browser console

1

I have an application in JS that runs via the browser console. I would like to know the possibilities of sending and receiving data via mysql through the Console.

I do not know if it's possible either.

I tried something, but it did not 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 in console

  

Uncaught ReferenceError: require is not defined

    
asked by anonymous 03.04.2018 / 17:30

0 answers