In Express.js, res.links() populates the response Link HTTP header. You pass an object whose keys are relation names (such as next and last) and whose values are URL strings—or arrays of URLs for the same relation.
GET /posts?page=1
→ Link includes first, last, self, next (no prev)
GET /posts?page=3
→ Link includes first, last, self, prev, next
GET /posts?page=5
→ Link includes first, last, self, prev (no next)
How It Works
Build a links object with the relations you always want.
Add prev/next only when valid so clients are not pointed past the ends.
Call res.links once with that object, then send JSON.
self helps clients know the canonical URL for this page.
Example 3 — Multiple URLs for One Relation
Pass a string array when one rel has several targets (docs: String | String[]).
GET /article
→ Link: <https://example.com/article.atom>; rel="alternate",
<https://example.com/article.json>; rel="alternate",
<https://example.com/series/intro>; rel="related"
→ {"title":"Express Link headers","body":"…"}
How It Works
Array value → multiple Link segments with the same rel.
String value → a single segment for that relation.
Mix both in one res.links() call.
Still send the body afterward with json or send.
Compatibility
Runtime Support
res.links() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Clients read the Link header from the HTTP response.
✓ Server · Express 4 & 5
res.links()
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not a browser API.
ServerNode.js runtime API
Node.js18+ for Express 5 · Express 4 supported
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
res.links()Express on Node.js
Bottom line: Study with Node.js and express. Use curl -i or DevTools Network to inspect the Link header.
Frequently Asked Questions
It joins an object of link relations (such as next and last) into the response Link HTTP header. Each property name becomes a rel value; each value is a URL string or an array of URLs.
Clients use it to discover related resources—especially pagination (next, prev, first, last)—without inventing a custom body shape.
No. It only sets the Link header. You still call res.json(), res.send(), or similar to finish the response.
Yes. Official type is Record<String, String | String[]>. Pass an array to emit multiple links for the same rel.
No. It is a stable Express 4 and Express 5 response method.