ctx.response.lastModified

Gets or sets the `Last-Modified` response header as a `Date` object.

Since Koa 2 Spec ↗

Syntax

ctx.response.lastModified = date  // or ctx.lastModified = date

Parameters

NameTypeRequiredDescription
date Date | string Yes A `Date` instance or a date string. Converted to HTTP date format (UTC).

Returns

Date | undefined — The parsed `Last-Modified` date, or `undefined` if not set.

Examples

import Koa from 'koa';
import { stat } from 'node:fs/promises';

const app = new Koa();

app.use(async (ctx) => {
  const { mtime } = await stat('./data.json');
  ctx.lastModified = mtime;
  ctx.set('ETag', `"${mtime.getTime()}"`);
  ctx.body = { data: 'example' };
});

app.listen(3000);
Output
Last-Modified: Sun, 18 May 2026 12:00:00 GMT
ETag: "1747566000000"

Notes

Used together with `ETag` for HTTP conditional request support (`If-Modified-Since` / `If-None-Match`). For static file serving, use `koa-static` which handles this automatically.

See also