how do i open a new page with express routing?

Viewed 31

How do you redirect the page back to index.html after the user submits changes to the database. Below is the post script that im using to update the database with the users inputs, but after the user submits the changes, the page stays on /user_create

router.post('/user_create', (req, res) => {
    const path = require('path');
    const id = req.body.create_id_number;
    const firstName = req.body.create_first_name;
    const lastName = req.body.create_last_name;
    const projectName = req.body.create_project_name;
    const location = req.body.create_location;
    const department = req.body.create_department_name;
    const queryString = 'INSERT INTO testTable (idtestTable, someInfo, otherInfo, lastName, firstName, department) VALUES (?, ?, ?, ?, ?, ?)';

    pool.query(queryString, [id, projectName, location, lastName, firstName, department], (err, results, fields) => {
      if(err) {
        console.log('Failed to inser new user: ', err);
        res.sendStatus(500);
        return;
      }

      console.log('Inserted a new user with id: ' + id);
      res.end();
    });
});

Right before res.end() i tried res.sendFile(path) but that does not seem to work.

0 Answers
Related