Categories
express javascript node.js response

How to use express response to stay in the same page without redirect?

Consider a simple form which takes email as input. Submit button calls a bootstrap modal in case authentication failed. If at success, it redirects to the next view.

When bootstrap modal appears, the browser is constantly loading the page, waiting a response.

I am using this code on server side:

app.post('/', (req, res) => {
Users.findOne({
email: req.body.email
})
.then(user => {
if (user) {
obj = req.body.email
res.redirect('/survey')
}
})
})

I tried to add an else statement in case user is not found:

...
else  {
console.log('User not found')
return
}

I do not want to redirect to the same page because modal will not work.

Is there a res method in order to achieve this?