node-fetch-server converts Node’s HTTP server interfaces into Request/Response flows that match modern runtimes.
Features
- Web Standards - Standard
RequestandResponseAPIs - Drop-in Integration - Works with
node:httpandnode:httpsmodules - Streaming Support - Response support with
ReadableStream - Custom Hostname - Configuration for deployment flexibility
- Client Info - Access to client connection info (IP address, port)
- TypeScript - Full TypeScript support with type definitions
Installation
Quick Start
Basic Server
Here’s a complete working example with a simple in-memory data store:Working with Request Data
Handle different types of request data using standard web APIs:Streaming Responses
Take advantage of web-standard streaming withReadableStream:
Custom Hostname Configuration
Configure custom hostnames for deployment on VPS or custom environments:Accessing Client Information
Get client connection details (IP address, port) for logging or security:HTTPS Support
Use with Node.js HTTPS module for secure connections:API Reference
createRequestListener(handler, options?)
Creates a request listener function that can be used with http.createServer() or https.createServer().
Parameters:
handler: FetchHandler- Function that handles the request and returns a Responseoptions?: RequestListenerOptions- Optional configurationhost?: string- Custom hostname to use in request URLs
(req: IncomingMessage, res: ServerResponse) => Promise<void>
FetchHandler
A function that handles an incoming request and returns a response.
ClientAddress
Information about the client that sent a request.
Low-level API
For more control over request/response handling, use the low-level API:createRequest(req, res, options)- Converts Node.js IncomingMessage to web RequestsendResponse(res, response)- Sends web Response using Node.js ServerResponse
- Building custom middleware systems
- Integrating with existing Node.js code
- Implementing custom error handling
- Performance-critical applications
Migration from Express
Transitioning from Express? Here’s a comparison of common patterns:Basic Routing
Related Packages
fetch-proxy- Build HTTP proxy servers using the web fetch API