Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Diferencia entre req.query y req.params

Queryパラメータを取得するには req.query を使います。

const express = require('express');
const app = express();

app.get('/hello', (req, res) => {
    res.send('Hello ' + req.query.name);
});

app.listen('3000', () => {
    console.log('Application started');
});
//http://localhost:3000/hello?name=Suzuki
res.send('Hello' + req.query.name);
$ Hello Suzuki

Pathパラメータを取得するには req.params を使います。

const express = require('express');
const app = express();

app.get('/hello/:name', (req, res) => {
    res.send('Hello ' + req.params.name);
});

app.listen('3000', () => {
    console.log('Application started');
});
//http://localhost:3000/hello/SuzukiTaro
res.send('Hello' + req.params.name);
$ Hello SuzukiTaro
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away