createNodeRequestHandler
function
Attaches metadata to the handler function to mark it as a special handler for Node.js environments.
createNodeRequestHandler
T
Attaches metadata to the handler function to mark it as a special handler for Node.js environments.
@paramhandler
T
- The handler function to be defined and annotated.
@returns
T
Usage Notes
Usage in an Express application:
const app = express();export default createNodeRequestHandler(app);
Usage in a Hono application:
const app = new Hono();export default createNodeRequestHandler(async (req, res, next) => { try { const webRes = await app.fetch(createWebRequestFromNodeRequest(req)); if (webRes) { await writeResponseToNodeResponse(webRes, res); } else { next(); } } catch (error) { next(error); }}));
Usage in a Fastify application:
const app = Fastify();export default createNodeRequestHandler(async (req, res) => { await app.ready(); app.server.emit('request', req, res); res.send('Hello from Fastify with Node Next Handler!');}));
Jump to details