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})
1const express = require('express');
2const bodyParser = require('body-parser');
3
4const app = express();
5app.use(bodyParser.urlencoded({ extended: true }));
6
7// POST /somepost/?name=somename
8app.post('/somepost', (req, res) => {
9 console.log('Name:', req.query.name);
10 res.status(200);
11});
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
1//get query¶ms in express
2
3//etc. example.com/user/000000?sex=female
4
5app.get('/user/:id', function(req, res) {
6 const query = req.query;// query = {sex:"female"}
7 const params = req.params; //params = {id:"000000"}
8
9})
10