Masnad Nihit Masnad Nihit - 1 month ago 4x
Node.js Question

router.get not posting multiple params

Hi so I am learning basics of node.js and express, and I was trying to submit a form with two parameters and trying to get that in the same screen.
But for some reason I guess I am not sure how to use router.get to get the both input fields parameters.
Here is my js file

var express = require('express');
var router = express.Router();

router.get('/:awesomeTitle?/:awesomeAuthor?', function(req, res, next) {
{title: req.params.awesomeTitle ? req.params.awesomeTitle : '' , author: req.params.awesomeAuthor ? req.params.awesomeAuthor : '' });
});'/', function(req, res, next) {
var awesomeTitle = req.body.title;
var awesomeAuthor =;
res.redirect('/' + awesomeTitle + awesomeAuthor);

module.exports = router;

And here is my hbs file.

<h1> Result </h1>
<form action="/" method="post">
<input type="text"/ name="title">
<input type="text"/ name="author">
<button type="submit">Submit</submit>

So just wanted to know how to get the awesome title and author from submit to the page again in the h1 and h2 tags.
P.S I am not sure how to debug this application so.. and it doesn't show any errors, all I get is both the input fields answer combined.


It looks like you're missing a / in your redirect. Try changing the last line in your post handler to this:

res.redirect('/' + awesomeTitle + '/' + awesomeAuthor);