ali haider ali haider - 4 months ago 12
Node.js Question

Page not getting rendered via Express when using post (NodeJS)

I am using Express v.2.4.6 (Node.js - v.0.6.2).
I am trying to render (or redirect to) a new page once POST is called (as opposed to GET). I am able to render/redirect when GET is called. However, I cannot seem to render a page when POST is called in Express. I am not sure if this is even possible though the guide on the Express site does mention an example where you can redirect once POST is called.
The relevant code is given below (client is sending the form in JSON). I can parse through the JSON message successfully in Node.j.

Sample route:

app.post('/signup', function(req, res){
res.redirect('index');
//res.render('index');
});


No exceptions are thrown, but the index page does not get rendered nor redirected.
Any feedback will be appreciated.

Answer

res.redirect('/') is most likely what you wanted there, but you can render in any route, redirecting is just a convention that most people use

Comments