Is it possible to run this JavaScript code in .html document:
<script>
function DBConnect() {
var mysql = require('mysql');
var mydb = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'admin123',
database: 'users'
});
var username = user_name.value;
mydb.connect();
var query = ('select passwd from peer where username=' + username);
console.log(query);
connection.end(function(err) {
// The connection is terminated now
});
}
</script>
Because when I'm trying always got an error: Undefined "require", or how can I call this function in other f.e.: db.js? I have already script server.js, that is running from Node.js, do you think the code above should be running here?