1app.get('/path/:name', function(req, res) { // url: /path/test
2 console.log(req.params.name); // result: test
3});
4
5// OR
6
7app.get('/path', function(req, res) { // url: /path?name='test'
8 console.log(req.query['name']); // result: test
9});
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})
7
8req.params refers to items with a ':' in the URL and req.query refers to items associated with the '?
1app.get('/p/:tagId', function(req, res) {
2 res.send("tagId is set to " + req.params.tagId);
3});
4
5// GET /p/5
6// tagId is set to 5
7
1// GET /something?color1=red&color2=blue
2
3app.get('/something', (req, res) => {
4 req.query.color1 === 'red' // true
5 req.query.color2 === 'blue' // true
6})