Express.js req.stale Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Request

Definition

In Express.js, req.stale is a Boolean that is true when the client’s cached copy is not considered fresh. Officially it is the opposite of req.fresh: req.stale === !req.fresh.

Use it for conditional GET/HEAD responses. When stale, send the full body (200). When fresh (!req.stale), send 304 Not Modified. Express compares If-None-Match / If-Modified-Since to your ETag / Last-Modified response headers.

Syntax

Read req.stale in your Express.js route handler. Start with this line.

Express
req.stale          // Boolean — opposite of req.fresh
req.fresh          // Boolean — client cache still valid
if (!req.stale) return res.status(304).end();
res.send(body);
CallWhat it does
req.stale // Boolean — opposite of req.freshPrimary signature.
req.fresh // Boolean — client cache still validRelated call form.
if (!req.stale) return res.status(304).end();Related call form.
res.send(body);Related call form.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

req.stale          // Boolean — opposite of req.fresh
req.fresh          // Boolean — client cache still valid
if (!req.stale) return res.status(304).end();
res.send(body);

Parameters

This Express.js property is read from the request or response — it has no call parameters.

Return Value

req.stale is a Boolean property — the inverse of req.fresh. When the cache validators do not match, it is true.

Express
res.set('ETag', etag);
if (req.stale) {
  res.send(body);
} else {
  res.status(304).end();
}

Express.js Examples

Example 1 — Send Body Only When Stale

Set an ETag, then use req.stale to choose 200 vs 304.

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

const BODY = { updated: true, items: [1, 2, 3] };
const ETAG = '"feed-v3"';

app.get('/feed', (req, res) => {
  res.set('ETag', ETAG);

  if (!req.stale) {
    // Client cache is still fresh
    return res.status(304).end();
  }

  res.json(BODY);
});

app.listen(3000);

How It Works

  1. Set the validator first. res.set('ETag', ETAG) must run before reading req.stale.
  2. Compare. Express checks If-None-Match against that ETag.
  3. Fresh → 304. !req.stale means the client already has a valid copy.
  4. Stale → full JSON. When validators miss or are absent, send the body.

Example 2 — Stale Check with Last-Modified

Same pattern using a modification time instead of an ETag.

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

const MODIFIED = new Date('2026-05-02T00:00:00Z');

app.get('/news', (req, res) => {
  res.set('Last-Modified', MODIFIED.toUTCString());

  if (req.fresh) {
    return res.status(304).end();
  }

  // req.stale === true here
  res.send('Fresh news payload');
});

app.listen(3000);

How It Works

  1. Advertise mtime. Last-Modified tells caches when the resource last changed.
  2. Client revalidates. Browsers send If-Modified-Since on later visits.
  3. Use either flag. if (req.fresh) is the same decision as if (!req.stale).
  4. Send only when needed. Stale requests get the full string body.

Example 3 — Let res.send Apply Freshness

Express helpers can emit 304 automatically when the request is fresh.

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

app.get('/page', (req, res) => {
  res.set('ETag', '"page-1"');
  // If req.fresh, res.send turns this into 304 with an empty body
  res.send('Hello, cached world');
});

app.listen(3000);

How It Works

  1. Still set ETag. Without validators, every request stays stale.
  2. res.send checks freshness. Internally it looks at req.fresh before writing the body.
  3. Fresh → 304. Matching If-None-Match skips the body.
  4. Explicit checks optional. Use manual req.stale when you need custom branching; otherwise res.send / res.json is enough.

Runtime Support

req.stale is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers send conditional headers; they do not expose req.stale.

✓ Server · Express 4 & 5

req.stale

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
req.stale Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is a Boolean that is true when the client’s cached copy is not considered fresh. Officially it is the opposite of req.fresh — when stale, send the full response.
req.stale is always !req.fresh. If the cache is still valid (fresh), send 304 Not Modified; if stale, send 200 with the body.
Express computes freshness by comparing request validators (If-None-Match / If-Modified-Since) to response headers already set on res. Set those headers before reading req.stale.
Yes. When you call res.send (and related helpers) with matching validators, Express can turn a fresh request into a 304 without an explicit check.
No. It is a server-side Express property. Browsers send conditional headers; your server decides 304 vs full body.

Next: req.subdomains

Read subdomain segments from the request host.

req.subdomains tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful