I'm trying to connect to my local mysql database by using node.js on my website. I have installed node.js on my laptop. This is my code that is executed:
function registerUser()
{
var mysql = require("mysql");
var connection = mysql.createConnection( {
host: 'localhost',
user: 'root',
password: '',
database: 'Fountaint_News_Database',
port: 3306
});
connection.connect();
var query = connection.query('INSERT INTO registered_users VALUES ("test", 22)',
function(err, result, fields) {
if (err) throw err;
console.log('result: ', result);
});
connection.end();
console.log('Connection closed');
}
I haven't done anything else, I'm not sure if there is anything else to setup, but when I runt I just get this error "ReferenceError: Can't find variable: require".
I hope that someone can help me.