getting url parameters express code example

Example 1: express get query params from url

GET /something?color1=red&color2=blue

app.get('/something', (req, res) => {
    req.query.color1 === 'red'  // true
    req.query.color2 === 'blue' // true
})

Example 2: express get url parameters

app.get('/path/:name', function(req, res) {
  res.send("tagId is set to " + req.params.name);
});

Example 3: expressjs query params

// GET /search?q=tobi+ferret
console.dir(req.query.q)
// => 'tobi ferret'

// GET /shoes?order=desc&shoe[color]=blue&shoe[type]=converse
console.dir(req.query.order)
// => 'desc'

console.dir(req.query.shoe.color)
// => 'blue'

console.dir(req.query.shoe.type)
// => 'converse'

// GET /shoes?color[]=blue&color[]=black&color[]=red
console.dir(req.query.color)
// => ['blue', 'black', 'red']

Example 4: node js express url parameters

// http://localhost:8080/api/1
app.get('/api/:version', function(req, res) {
    res.send(req.params.version);
});

Example 5: express route parameters

app.get('/users/:userId/books/:bookId', function (req, res) {
  res.send(req.params)
})

Example 6: express route parameters

app.get('/',function(req,res)
{
    res.send("Route path at base address");
});