“Node Express Params” Respostas de código

Express JS params

app.get('/path/:name', function(req, res) { // url: /path/test
  console.log(req.params.name);  // result: test
});

// OR

app.get('/path', function(req, res) {  // url: /path?name='test'
  console.log(req.query['name']);  // result: test
});
Ham-Solo

Express Get Params depois?

GET /something?color1=red&color2=blue

app.get('/something', (req, res) => {
    req.query.color1 === 'red'  // true
    req.query.color2 === 'blue' // true
})

req.params refers to items with a ':' in the URL and req.query refers to items associated with the '?
Batman

Node Express Params

// url = /something/2?color1=red&color2=blue&type=square

app.get('/something/:id', (req, res) => {
  	req.params.id  === 2 // true
    req.query.color1 === 'red'  // true
    req.query.color2 === 'blue' // true
    req.query.type === 'square' // true
})
miletoo

Parâmetros de rota expressos

Route path: /flights/:from-:to
Request URL: http://localhost:3000/flights/LAX-SFO
req.params: { "from": "LAX", "to": "SFO" }
Motionless Mouse

Respostas semelhantes a “Node Express Params”

Perguntas semelhantes a “Node Express Params”

Mais respostas relacionadas para “Node Express Params” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código