app.get()
Routes HTTP GET requests for a path to one or more handler functions.
Syntax
app.get(path, ...handlers) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path | string | RegExp | Yes | The route path or pattern, e.g. `/users/:id`. |
handlers | ...function | Yes | One or more `(req, res, next)` middleware/handler functions. |
Returns
Application — The app instance, for chaining.
Examples
app.get('/users/:id', (req, res) => {
res.json({ id: req.params.id });
});
Output
$ curl localhost:3000/users/7
{"id":"7"}
app.get('/admin', requireAuth, (req, res) => {
res.send('admin area');
});
Output
$ curl localhost:3000/admin
admin area
Notes
`app.get(name)` with a single string argument instead reads an app
setting, so always pass a handler for routing. In Express 5 optional
params use `:id?` only as a named group and the path-matching engine
changed (no bare `*`/`(.*)` regex strings). The last handler should
end the response.