Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Lets say I have this code saved in index.js:

JavaScript
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() {

// Create Account
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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900