“Ekspres JS Params” Kode Jawaban

Ekspres 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 setelah?

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

Ekspres mendapatkan parameter URL

app.get('/path/:name', function(req, res) {
  res.send("tagId is set to " + req.params.name);
});
Batman

Ekspres Param dalam URL

app.get('/p/:tagId', function(req, res) {
  res.send("tagId is set to " + req.params.tagId);
});

// GET /p/5
// tagId is set to 5
SirSundays

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

Jawaban yang mirip dengan “Ekspres JS Params”

Pertanyaan yang mirip dengan “Ekspres JS Params”

Lebih banyak jawaban terkait untuk “Ekspres JS Params” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya