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})
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);
1const querystring = require('querystring');
2const url = "http://example.com/index.html?code=string&key=12&id=false";
3const qs = "code=string&key=12&id=false";
4
5console.log(querystring.parse(qs));
6// > { code: 'string', key: '12', id: 'false' }
7
8console.log(querystring.parse(url));
1const url = require('url');
2
3// new URL object
4const current_url = new URL('http://usefulangle.com/preview?id=123&type=article');
5
6// get access to URLSearchParams object
7const search_params = current_url.searchParams;
8
9// get url parameters
10const id = search_params.get('id');
11const type = search_params.get('type');
12
13// "123"
14console.log(id);
15
16// "article"
17console.log(type);
18