The average node js chatbot tutorial ends the moment a reply appears. Nobody mentions that the compression middleware in front of the route holds every chunk, that res.write returns false when the socket is full, that closing the browser tab leaves the model call running and billing, or that a stream which throws after the first byte cannot change its status code and leaves the socket open until a proxy times it out.
This is a build guide, not a system prompt. Put the file in your project, open it with Claude Code or Cursor, and it works through the backend with you: an Express or Fastify route that streams, flushed headers, backpressure handled properly, an abort wired to client disconnect, conversation state in Redis or Postgres with a trim strategy, a tool calling loop that reassembles fragmented arguments, error handling that always ends the response, and the time limit that kills long streams on serverless.
Pay once and the file is yours for good. Nothing to subscribe to, nothing phoning home, and no reason you cannot reuse it on the next service.