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?
- 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
- you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
Sign upLogin