require
doesn't exist on the client (at least not natively). The code you have is meant to be run on the server (node.js).
Try putting this into a file, say main.js
, and then run node main.js
.
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!");
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…