Lets say I have this code saved in
index.js
:
const serveIndex = require('serve-index');
const express = require('express');
const app = express();
app.use('/project', express.static('public'))
app.use('/project', serveIndex('public'))
app.get('/', (req, res) => {
res.send('Server Running.');
});
function createAccount() {
var mysql = require("mysql");
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "database1"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO `users` (`username`, `password`, `email`, `confirm_code`, `confirmed`, `plugin1`, `plugin2`, `plugin3`, `plugin4`, `plugin5`, `myplugin1`, `myplugin2`, `myplugin3`, `myplugin4`, `myplugin5`) VALUES ('" + username + "', '" + password + "', '" + email + "', '" + code + "', 'no', 'none', 'none','none', 'none', 'none', 'none', 'none', 'none', 'none', 'none');";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
app.listen(3000, () => console.log('App running on port 3000.'));
And in my
public
file, I have a javascript file running this:
var username = "John Doe";
var password = "1234";
var email = "johndoe@example.com";
var code = "1234";
createAccount();
How do I get the
createAccount()
function to run properly when the js file in the public folder is run? (As in it creates the account with all the information provided in variables)
What I have tried:
I have tried what you see here, and I searched the internet for an answer but couldn't find one.