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});
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// http://localhost:8080/api/1
2app.get('/api/:version', function(req, res) {
3 res.send(req.params.version);
4});
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})