How can I create search result page on



var express = require('express')
var n = req.query.query;
mysql_crawl.query('SELECT prod_name, full_price FROM `xxx` WHERE MATCH(data_index) AGAINST("'+n+'")', function(error, product_data) {
res.render('result.html', {result: n, related: product_data: product_data})


<form action= '/results' class="input-group input-group-lg" id="search">
         <input type="text" class="input-group form-control"  name="query" value='<%= result %>'/>
               <span class="input-group-btn">
                     <button class="btn btn-secondary" type='button'>Search</button>

When I search, I get a URL like, but I want a results page at

Both pages should be the same results. If I change the keyword in the URL, it should show search results for that keyword.

So my question is, how do I create the page to duplicate the results at

Problem courtesy of: Moomoo Soso


You can create new route as

app.get('/s/:keyword', function (req, res) {
    var n = req.params.keyword;
    // do rest of the task

Instead of repeating same code in two route, you can create a function then call the same function in both routes.

Solution courtesy of: vartika


app.get('/s/price/:sea_query', function (req, res) {
    var n = req.params.sea_query;

I can use this to get data from url, thanks :)

Discussion courtesy of: Moomoo Soso

This recipe can be found in it's original form on Stack Over Flow.