I am trying to connect to MYSQL database.
My code:
E-mail: <input type="email" id="email" size=25><br>
<button id="go" onclick="register()">Go</button>
<script type="text/javascript">
function register(){
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
}
</script>
When I open console it shows:
Uncaught ReferenceError: require is not defined
I have nodejs installed and have also installed MYSQL from cmd using the command:
npm install mysql
What is wrong here?