title: How to return a message to user that the email they input has been registered and redirect to register page?
body: <p>(solved)</p>
  <p>I am writing a register page. There is a problem I face right now. I have two HTML pages <code>index.html</code> and <code>register.html</code>. When the users submit their informations in <code>register.html</code>, I want my code to first to check if their input email has already exists in the database. My register function as following:</p>
  <pre><code>   app.post('/user_register', (req, res) =&gt; {
        const name = req.body.input_name;
        const email = req.body.input_email;
        const phoneNumber = req.body.input_phonenumber;
        const password = req.body.input_password;
        const confirmpassword = req.body.input_confirmpassword;
        const postQuery = 'INSERT INTO registerinfo VALUE (?,?,?,?)';
        const checkQuery = 'SELECT email FROM registerinfo WHERE email = ?';
      
        mysqlConnect.connection.query(checkQuery, [email], async (err, result, fields) =&gt; {
              if (err) console.log(err);
              if (result.length &gt; 0) {
                  return app.get('/result', (req, res)=&gt;{
                      res.json(result);
                      res.redirect('/register')
                  })
              
                  
              } else {
                  let hashedPassword = await bcryptjs.hash(password, 8);
                  mysqlConnect.connection.query(postQuery, [name, email, phoneNumber, hashedPassword], (err, result, fields) =&gt; {
                      if (!err) {
                          console.log('Register SUCCESSFUL!!')
                      } else {
                          console.log(`the error is ${err}`)
                          res.send(500);
                          throw err;
                      }
                  })
              } 
      })// query end here
  </code></pre>
  <p>The problem start from <code>if (result.length &gt; 0){}</code>, my thought is if <code>result.lenght &gt; 0</code> as email exists already in database, then use <code>return app.get()</code> to send json data to route <code>/result</code> and redirect back to <code>register.html</code>, <code>register.html</code> will always fetch data from route <code>/result</code>, if data is not empty, then span a message to users that this email has already been registered.</p>
  <p>First of all, redirect back to <code>register.html</code> is not working, I tried <code>res.redirect('/register')</code> and <code>res.sendFile(__dirname + './public/register.html')</code> inside <code>return</code>, but once I click submit, it will always get back to <code>index.html</code>.</p>
  <p>Second, is my thought the right way to achieve what I want? When I look at it, this <code>return app.get()</code> inside <code>app.post()</code> doesn't look like the right way to do it. And I did find a solution online using handlebars, where it solve this simply with <code>return res.render('register', {message: 'email is registered '})</code>, since I didn't use hbs, I try to solve this without it. So if my thought to solve this is wrong to begin with, what is the right way to do it?</p>