I’m new to node, express and jade and I’m making a small app that asks for a name and a password with a simple form and then redirects the user to the path that belongs to their username.
Here’s the code for doing that:
Express first part (app.js):
(...)
app.get('/', function(req, res){
res.render('index');
});
(...)
Jade part (index.jade):
p Log In
form(method='post', action='/')
p
label User
input(type='text',name='user')
p
label Password
input(type='password', name='pass')
p
input(type='submit', name='submit')
Express second part (app.js):
(...)
app.post('/', function(req, res){
//Handle request form
res.render('user', {
locals: {
user: req.body.user
}
})
});
(...)
For example:
username: roger
Passwor: 1234
Submit
Then when clicks submit I wanna redirect the user to:
I hope that I’ve explained myself as well as I can.
I think you’re looking for this:
Then you’ll need another router to handle the rendering part:
http://expressjs.com/guide.html#http-methods