reply.raw

The underlying Node.js http.ServerResponse object.

Since Fastify 5 Spec ↗

Syntax

reply.raw

Returns

ServerResponse — The native Node response stream.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.get('/sse', (_req, reply) => {
  reply.hijack();
  reply.raw.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    Connection: 'keep-alive',
  });
  const timer = setInterval(() => {
    reply.raw.write(`data: ${Date.now()}\n\n`);
  }, 1000);
  reply.raw.on('close', () => clearInterval(timer));
});

Notes

Writing directly to reply.raw bypasses Fastify serialization and hooks; pair it with reply.hijack() and clean up on the 'close' event. Prefer the high-level API unless you need raw streaming.