Client identification
Inspect the User-Agent sent by a client.
Express.js · Module
Retrieves the value of an HTTP request header by name. Use it inside a route or middleware callback to inspect client-supplied request metadata.
req.get() retrieves the value of a named HTTP request header. Header-name matching is case-insensitive, and the method returns the header value when present or undefined when absent.
req.get(field)| Name | Type | Description |
|---|---|---|
header | string | The name of the HTTP request header to retrieve. |
The value of the requested header, or undefined when the header is not present.
req.get() can inspect.req.get() is one of the request methods available for working with incoming HTTP requests.req includes Node’s built-in request capabilities, so use req.get() specifically when you want Express’s header lookup helper.const express = require('express');
const app = express();
app.get('/profile', (req, res) => {
const userAgent = req.get('User-Agent');
res.json({ userAgent });
});
app.listen(3000);Reads the request's User-Agent header and returns it as JSON.
Inspect the User-Agent sent by a client.
Read an Accept or Content-Type-related request header.
Use a custom header to apply request-specific logic.
reqreq.headersreq.headerapp.getrouter.get