2
votes

app.post is not documented in expressjs.com. As I understand, the server listens to a url requestion / etc. which then invokes a middleware and a callback. But all this is same in app.get.

What unique value does it provide to express?

PS. There are other questions like Express Framework app.post and app.get, or app.use and app.get (or app.post) node.js express but reading answers to the same does not provide the answer to teh question.

Edit:

The following code provides for invocation of both app.get and app.post on /login request from the browswer. Are both app.get and app.post invoked? (Presumably in the order of appearance. )

app.get('/login', function(req, res){
var username = req.user ? req.user.username : ''; res.render('login', { title: 'authenticate', username: username,
});
message: req.flash('error') });
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }), function(req, res) {
res.redirect('/admin'); });

enter code here
1

1 Answers

2
votes

I'd not say it's not documented, but basically it does the same as app.get() does for HTTP GET, but instead only matches HTTP POST requests.

If you don't know what the difference between a POST and a GET is, you can for example take a look here.

As for your sample code, either your get or your post handler is invoked, depending on whether the browser does a post or a get request. Both are never invoked for the same request.