bbennett36 bbennett36 - 10 months ago 68
HTTP Question

How to pass GET form data to Express?

I have a form

<form action="./search" method="GET">
<div class="form-group text-center">
<input type="text" name="keyword" placeholder="Job Title" />
<button type="submit" class="btn btn-primary">Find Jobs</button>

If I enter "akron" in the form and submit and pass it to this next method it returns "Cannot GET /search?keyword=akron"

router.get('/search/:keyword', function(req, res) {
res.send('hello ' + req.params.keyword + '!');

But if I type http://localhost:3000/search/hello it will return the "hello akron!"

What is the correct way to pass the parameters?

Answer Source

Change to


The "./blah" syntax with dot in front is for files.