I am new to nodeJS and I have been trying to create a registration form with validation.
The validation part is complete with sql query statements, but I am having trouble redirecting from my server side back to registration form with a message info such as 'Email address already exists'.
How do I process this on the client 'register.js' ?
register.js
<form id='register-form' method="POST" action="http://localhost:3306/register">
server.js
app.post('/register', (req,res) => {
var email = req.body.email;
var password = req.body.password;
let sql = "SELECT * FROM user WHERE email='" + email + "'";
db.query(sql,(err,result) => {
if (err) throw err;
if (result.length > 0) {
console.log("user already exists");
res.redirect('http://localhost:3000/#/Register');
} else {
insertUser(email,password);
res.send(email + " has been added to database");
}