1GET /something?color1=red&color2=blue
2
3app.get('/something', (req, res) => {
4 req.query.color1 === 'red' // true
5 req.query.color2 === 'blue' // true
6})
1app.get("/users/:id",(req,res)=>{ // https://domain.com/users/817178
2 const id = req.params.id ; // 817178
3})
4app.get("/users?name=anas",(req,res)=> { // https://domain.com/users?name=anas
5const name = req.query.name ; //anas
6})
1var express = require('express');
2var app = express();
3
4app.get('/', function(req, res){
5 res.send('id: ' + req.query.id);
6});
7
8app.listen(3000);
1// GET /search?q=tobi+ferret
2console.dir(req.query.q)
3// => 'tobi ferret'
4
5// GET /shoes?order=desc&shoe[color]=blue&shoe[type]=converse
6console.dir(req.query.order)
7// => 'desc'
8
9console.dir(req.query.shoe.color)
10// => 'blue'
11
12console.dir(req.query.shoe.type)
13// => 'converse'
14
15// GET /shoes?color[]=blue&color[]=black&color[]=red
16console.dir(req.query.color)
17// => ['blue', 'black', 'red']
18