node:http
Node-compatible HTTP/1.1 client and server APIs (node:http).
Available in vjs only (not available in vjs-lite). Enabled by default
unless --no-node-compat is passed.
import ... from "node:http"
node-compat (enabled by default in vjs; absent in vjs-lite; disable with --no-node-compat)Example
Section titled “Example”import { createServer } from "node:http";
const server = createServer((req, res) => { res.writeHead(200, { "content-type": "text/plain" }); res.end("ok");});server.listen(0, "127.0.0.1");createServervjs onlyv0.0.0-alpha.2Server.requestvjs onlyv0.0.0-alpha.2options.getvjs onlyv0.0.0-alpha.2request() that forces method "GET" and automatically calls .end().validateHeaderNamevjs onlyv0.0.0-alpha.2validateHeaderValuevjs onlyv0.0.0-alpha.2Agentvjs onlyv0.0.0-alpha.2IncomingMessagevjs onlyv0.0.0-alpha.2OutgoingMessagevjs onlyv0.0.0-alpha.2ClientRequest and ServerResponse for managing outgoing HTTP headers and body streams.ServerResponsevjs onlyv0.0.0-alpha.2RequestListener.ClientRequestvjs onlyv0.0.0-alpha.2request() and get().Servervjs onlyv0.0.0-alpha.2createServer().AbortSignalLikevjs onlyv0.0.0-alpha.2AgentOptionsvjs onlyv0.0.0-alpha.2new Agent(options).RequestOptionsvjs onlyv0.0.0-alpha.2request(), get(), and new ClientRequest().ServerOptionsvjs onlyv0.0.0-alpha.2createServer() and new Server().IncomingHttpHeadersvjs onlyv0.0.0-alpha.2OutgoingHttpHeadervjs onlyv0.0.0-alpha.2OutgoingHttpHeadersvjs onlyv0.0.0-alpha.2RequestListenervjs onlyv0.0.0-alpha.2Server.METHODSvjs onlyv0.0.0-alpha.2STATUS_CODESvjs onlyv0.0.0-alpha.2200, 404) to standard reason phrases (for example "OK", "Not Found").globalAgentvjs onlyv0.0.0-alpha.2Agent used when no custom agent is supplied.maxHeaderSizevjs onlyv0.0.0-alpha.216384).Functions
Section titled “Functions”createServer
Section titled “createServer”export function createServer(requestListener?: RequestListener): Server;
export function createServer(
options: ServerOptions,
requestListener?: RequestListener,
): Server;
Create a new HTTP Server.
createServer(requestListener?)| Name | Type | Description |
|---|---|---|
requestListener optional | RequestListener | Optional "request" event listener. |
Server — New HTTP Server.createServer(options, requestListener?)Create a new HTTP Server with explicit options.
| Name | Type | Description |
|---|---|---|
options | ServerOptions | Server configuration. |
requestListener optional | RequestListener | Optional "request" event listener. |
Server — New HTTP Server.request
Section titled “request”export function request(
options: RequestOptions | string | import("node:url").URL,
callback?: (res: IncomingMessage) => void,
): ClientRequest;
export function request(
url: string | import("node:url").URL,
options: RequestOptions,
callback?: (res: IncomingMessage) => void,
): ClientRequest;
Initiate an HTTP request using options.
request(options, callback?)| Name | Type | Description |
|---|---|---|
options | RequestOptions | string | import("node:url").URL | Request options or URL string. |
callback optional | (res: IncomingMessage) => void | Optional "response" listener. |
ClientRequest — Outgoing ClientRequest.request(url, options, callback?)Initiate an HTTP request to url with explicit options.
| Name | Type | Description |
|---|---|---|
url | string | import("node:url").URL | Target URL string or URL. |
options | RequestOptions | Request options merged over url. |
callback optional | (res: IncomingMessage) => void | Optional "response" listener. |
ClientRequest — Outgoing ClientRequest.export function get(
options: RequestOptions | string | import("node:url").URL,
callback?: (res: IncomingMessage) => void,
): ClientRequest;
export function get(
url: string | import("node:url").URL,
options: RequestOptions,
callback?: (res: IncomingMessage) => void,
): ClientRequest;
Convenience wrapper around request() that forces method "GET" and
automatically calls .end().
get(options, callback?)| Name | Type | Description |
|---|---|---|
options | RequestOptions | string | import("node:url").URL | Request options or URL string. |
callback optional | (res: IncomingMessage) => void | Optional "response" listener. |
ClientRequest — Outgoing ClientRequest.get(url, options, callback?)Convenience "GET" request to url with explicit options.
| Name | Type | Description |
|---|---|---|
url | string | import("node:url").URL | Target URL string or URL. |
options | RequestOptions | Request options merged over url. |
callback optional | (res: IncomingMessage) => void | Optional "response" listener. |
ClientRequest — Outgoing ClientRequest.validateHeaderName
Section titled “validateHeaderName”export function validateHeaderName(name: string): void;
Validate an HTTP header name against RFC 7230 token syntax.
| Name | Type | Description |
|---|---|---|
name | string | Header name to validate. |
voidTypeError— withcode = "ERR_INVALID_HTTP_TOKEN"when invalid.
validateHeaderValue
Section titled “validateHeaderValue”export function validateHeaderValue(name: string, value: unknown): void;
Validate an HTTP header value for prohibited control or CRLF characters.
| Name | Type | Description |
|---|---|---|
name | string | Header name (used in error diagnostics). |
value | unknown | Header value to validate. |
voidTypeError— withcode = "ERR_INVALID_CHAR"or"ERR_HTTP_INVALID_HEADER_VALUE"when invalid.
Classes
Section titled “Classes”export class Agent {
maxSockets: number;
maxTotalSockets: number;
maxFreeSockets: number;
readonly sockets: Record<string, unknown[]>;
readonly freeSockets: Record<string, unknown[]>;
readonly requests: Record<string, ClientRequest[]>;
constructor(options?: AgentOptions);
destroy(): void;
getName(options?: RequestOptions): string;
}
Connection-pooling agent managing client HTTP sockets.
constructor(options?: AgentOptions);
Construct a new HTTP Agent.
| Name | Type | Description |
|---|---|---|
options optional | AgentOptions | Optional connection pooling and keep-alive settings. |
| Property | Type | Description | Since |
|---|---|---|---|
maxSockets | number | Maximum concurrent sockets per host key. | v0.0.0-alpha.2 |
maxTotalSockets | number | Maximum total concurrent sockets across all hosts. | v0.0.0-alpha.2 |
maxFreeSockets | number | Maximum idle keep-alive sockets retained per host key. | v0.0.0-alpha.2 |
sockets readonly | Record<string, unknown[]> | Active sockets keyed by getName() destination string. | v0.0.0-alpha.2 |
freeSockets readonly | Record<string, unknown[]> | Idle keep-alive sockets keyed by getName() destination string. | v0.0.0-alpha.2 |
requests readonly | Record<string, ClientRequest[]> | Queued pending requests keyed by getName() destination string. | v0.0.0-alpha.2 |
Agent.destroy
Section titled “Agent.destroy”destroy(): void;
Destroy all sockets currently managed by this agent.
voidAgent.getName
Section titled “Agent.getName”getName(options?: RequestOptions): string;
Return the canonical pool key string for options.
| Name | Type | Description |
|---|---|---|
options optional | RequestOptions | — |
stringIncomingMessage
Section titled “IncomingMessage”export class IncomingMessage {
readonly aborted: boolean;
readonly complete: boolean;
readonly headers: IncomingHttpHeaders;
readonly headersDistinct: Record<string, string[]>;
readonly httpVersion: string;
readonly httpVersionMajor: number;
readonly httpVersionMinor: number;
method?: string;
readonly rawHeaders: string[];
readonly rawTrailers: string[];
readonly socket: unknown;
statusCode?: number;
statusMessage?: string;
readonly trailers: Record<string, string | undefined>;
readonly trailersDistinct: Record<string, string[]>;
url?: string;
readonly readable: boolean;
readonly readableEnded: boolean;
readonly destroyed: boolean;
constructor(socket: unknown);
setTimeout(msecs: number, callback?: () => void): this;
setEncoding(encoding: string): this;
read(size?: number): any;
pause(): this;
resume(): this;
destroy(error?: Error): this;
pipe<T extends { write(chunk: any, ...args: any[]): any; end(...args: any[]): any }>(
destination: T,
options?: { end?: boolean },
): T;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
emit(eventName: string | symbol, ...args: any[]): boolean;
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
}
Readable stream representing an inbound HTTP server request or client response.
constructor(socket: unknown);
Construct an IncomingMessage.
| Name | Type | Description |
|---|---|---|
socket | unknown | Underlying socket object. |
| Property | Type | Description | Since |
|---|---|---|---|
aborted readonly | boolean | true if the message was aborted before completion. | v0.0.0-alpha.2 |
complete readonly | boolean | true once the complete HTTP message has been received. | v0.0.0-alpha.2 |
headers readonly | IncomingHttpHeaders | Parsed lowercased request/response headers. | v0.0.0-alpha.2 |
headersDistinct readonly | Record<string, string[]> | Parsed headers with every key mapped to an array of values. | v0.0.0-alpha.2 |
httpVersion readonly | string | HTTP protocol version string (for example "1.1"). | v0.0.0-alpha.2 |
httpVersionMajor readonly | number | HTTP major version number. | v0.0.0-alpha.2 |
httpVersionMinor readonly | number | HTTP minor version number. | v0.0.0-alpha.2 |
method optional | string | HTTP request method ("GET", "POST", etc.) on server requests. | v0.0.0-alpha.2 |
rawHeaders readonly | string[] | Raw alternating [name, value, ...] header array in wire order. | v0.0.0-alpha.2 |
rawTrailers readonly | string[] | Raw alternating [name, value, ...] trailer array. | v0.0.0-alpha.2 |
socket readonly | unknown | Underlying connection socket. | v0.0.0-alpha.2 |
statusCode optional | number | HTTP response status code (for client responses). | v0.0.0-alpha.2 |
statusMessage optional | string | HTTP response status reason phrase (for client responses). | v0.0.0-alpha.2 |
trailers readonly | Record<string, string | undefined> | Parsed HTTP trailers received after the body. | v0.0.0-alpha.2 |
trailersDistinct readonly | Record<string, string[]> | Parsed HTTP trailers with array values. | v0.0.0-alpha.2 |
url optional | string | Request URL path and query string on server requests. | v0.0.0-alpha.2 |
readable readonly | boolean | Whether the stream is currently readable. | v0.0.0-alpha.2 |
readableEnded readonly | boolean | Whether "end" has been emitted. | v0.0.0-alpha.2 |
destroyed readonly | boolean | Whether destroy() has been called. | v0.0.0-alpha.2 |
IncomingMessage.setTimeout
Section titled “IncomingMessage.setTimeout”setTimeout(msecs: number, callback?: () => void): this;
Set inactivity timeout on the underlying socket.
| Name | Type | Description |
|---|---|---|
msecs | number | — |
callback optional | () => void | — |
thisIncomingMessage.setEncoding
Section titled “IncomingMessage.setEncoding”setEncoding(encoding: string): this;
Set character encoding for emitted "data" chunks.
| Name | Type | Description |
|---|---|---|
encoding | string | — |
thisIncomingMessage.read
Section titled “IncomingMessage.read”read(size?: number): any;
Pull buffered body chunks.
| Name | Type | Description |
|---|---|---|
size optional | number | — |
anyIncomingMessage.pause
Section titled “IncomingMessage.pause”pause(): this;
Pause "data" event emission.
thisIncomingMessage.resume
Section titled “IncomingMessage.resume”resume(): this;
Resume "data" event emission.
thisIncomingMessage.destroy
Section titled “IncomingMessage.destroy”destroy(error?: Error): this;
Destroy the message stream.
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisIncomingMessage.pipe
Section titled “IncomingMessage.pipe”pipe<T extends { write(chunk: any, ...args: any[]): any; end(...args: any[]): any }>(
destination: T,
options?: { end?: boolean },
): T;
Pipe body chunks into destination.
| Name | Type | Description |
|---|---|---|
destination | T | — |
options optional | { end?: boolean } | — |
TIncomingMessage.on
Section titled “IncomingMessage.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisIncomingMessage.once
Section titled “IncomingMessage.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisIncomingMessage.off
Section titled “IncomingMessage.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisIncomingMessage.emit
Section titled “IncomingMessage.emit”emit(eventName: string | symbol, ...args: any[]): boolean;
Synchronously emit an event.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
...args | any[] | — |
booleanIncomingMessage.[Symbol.asyncIterator]
Section titled “IncomingMessage.[Symbol.asyncIterator]”[Symbol.asyncIterator](): AsyncIterableIterator<any>;
Iterate asynchronously over body chunks.
OutgoingMessage
Section titled “OutgoingMessage”export class OutgoingMessage {
readonly headersSent: boolean;
sendDate: boolean;
readonly req?: IncomingMessage;
readonly writable: boolean;
readonly writableEnded: boolean;
readonly writableFinished: boolean;
readonly destroyed: boolean;
readonly closed: boolean;
readonly errored: Error | null;
constructor();
appendHeader(name: string, value: OutgoingHttpHeader): this;
flushHeaders(): void;
getHeader(name: string): OutgoingHttpHeader | undefined;
getHeaderNames(): string[];
getHeaders(): OutgoingHttpHeaders;
hasHeader(name: string): boolean;
removeHeader(name: string): void;
setHeader(name: string, value: OutgoingHttpHeader): this;
setTimeout(msecs: number, callback?: () => void): this;
addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<readonly [string, string]>): void;
write(chunk: string | Uint8Array, callback?: (error?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (error?: Error | null) => void): boolean;
end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;
end(chunk: string, encoding: string, callback?: () => void): this;
cork(): void;
uncork(): void;
destroy(error?: Error): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
emit(eventName: string | symbol, ...args: any[]): boolean;
}
Base class shared conceptually by ClientRequest and ServerResponse for
managing outgoing HTTP headers and body streams.
constructor();
Construct an OutgoingMessage.
| Property | Type | Description | Since |
|---|---|---|---|
headersSent readonly | boolean | true once HTTP headers have been flushed to the wire. | v0.0.0-alpha.2 |
sendDate | boolean | Automatically emit a Date response header (default true). | v0.0.0-alpha.2 |
req readonly optional | IncomingMessage | Associated IncomingMessage, when applicable. | v0.0.0-alpha.2 |
writable readonly | boolean | Whether the stream is currently writable. | v0.0.0-alpha.2 |
writableEnded readonly | boolean | Whether end() has been called. | v0.0.0-alpha.2 |
writableFinished readonly | boolean | Whether "finish" has been emitted. | v0.0.0-alpha.2 |
destroyed readonly | boolean | Whether destroy() has been called. | v0.0.0-alpha.2 |
closed readonly | boolean | Whether "close" has been emitted. | v0.0.0-alpha.2 |
errored readonly | Error | null | Error passed to destroy(err), or null. | v0.0.0-alpha.2 |
OutgoingMessage.appendHeader
Section titled “OutgoingMessage.appendHeader”appendHeader(name: string, value: OutgoingHttpHeader): this;
Append value to an existing outgoing header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
value | OutgoingHttpHeader | — |
thisOutgoingMessage.flushHeaders
Section titled “OutgoingMessage.flushHeaders”flushHeaders(): void;
Flush queued outgoing HTTP headers immediately.
voidOutgoingMessage.getHeader
Section titled “OutgoingMessage.getHeader”getHeader(name: string): OutgoingHttpHeader | undefined;
Retrieve the current value of outgoing header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
OutgoingHttpHeader | undefinedOutgoingMessage.getHeaderNames
Section titled “OutgoingMessage.getHeaderNames”getHeaderNames(): string[];
Return lowercased names of all queued outgoing headers.
string[]OutgoingMessage.getHeaders
Section titled “OutgoingMessage.getHeaders”getHeaders(): OutgoingHttpHeaders;
Return a shallow copy of all queued outgoing headers.
OutgoingMessage.hasHeader
Section titled “OutgoingMessage.hasHeader”hasHeader(name: string): boolean;
Return true if outgoing header name has been set.
| Name | Type | Description |
|---|---|---|
name | string | — |
booleanOutgoingMessage.removeHeader
Section titled “OutgoingMessage.removeHeader”removeHeader(name: string): void;
Delete outgoing header name before headers are sent.
| Name | Type | Description |
|---|---|---|
name | string | — |
voidOutgoingMessage.setHeader
Section titled “OutgoingMessage.setHeader”setHeader(name: string, value: OutgoingHttpHeader): this;
Set or overwrite outgoing header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
value | OutgoingHttpHeader | — |
thisOutgoingMessage.setTimeout
Section titled “OutgoingMessage.setTimeout”setTimeout(msecs: number, callback?: () => void): this;
Set socket inactivity timeout in milliseconds.
| Name | Type | Description |
|---|---|---|
msecs | number | — |
callback optional | () => void | — |
thisOutgoingMessage.addTrailers
Section titled “OutgoingMessage.addTrailers”addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<readonly [string, string]>): void;
Add trailing HTTP headers sent after the chunked body.
| Name | Type | Description |
|---|---|---|
headers | OutgoingHttpHeaders | ReadonlyArray<readonly [string, string]> | — |
voidOutgoingMessage.write
Section titled “OutgoingMessage.write”write(chunk: string | Uint8Array, callback?: (error?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (error?: Error | null) => void): boolean;
Write a body chunk.
write(chunk, callback?)| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | — |
callback optional | (error?: Error | null) => void | — |
booleanwrite(chunk, encoding, callback?)Write a string body chunk with explicit encoding.
| Name | Type | Description |
|---|---|---|
chunk | string | — |
encoding | string | — |
callback optional | (error?: Error | null) => void | — |
booleanOutgoingMessage.end
Section titled “OutgoingMessage.end”end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;
end(chunk: string, encoding: string, callback?: () => void): this;
Finish writing the HTTP message.
end(callback?)| Name | Type | Description |
|---|---|---|
callback optional | () => void | — |
thisend(chunk, callback?)Write a final chunk and finish the HTTP message.
| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | — |
callback optional | () => void | — |
thisend(chunk, encoding, callback?)Write a final string chunk with encoding and finish the HTTP message.
| Name | Type | Description |
|---|---|---|
chunk | string | — |
encoding | string | — |
callback optional | () => void | — |
thisOutgoingMessage.cork
Section titled “OutgoingMessage.cork”cork(): void;
Buffer subsequent writes in memory.
voidOutgoingMessage.uncork
Section titled “OutgoingMessage.uncork”uncork(): void;
Flush buffered writes.
voidOutgoingMessage.destroy
Section titled “OutgoingMessage.destroy”destroy(error?: Error): this;
Destroy the outgoing message stream.
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisOutgoingMessage.on
Section titled “OutgoingMessage.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisOutgoingMessage.once
Section titled “OutgoingMessage.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisOutgoingMessage.off
Section titled “OutgoingMessage.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisOutgoingMessage.emit
Section titled “OutgoingMessage.emit”emit(eventName: string | symbol, ...args: any[]): boolean;
Synchronously emit an event.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
...args | any[] | — |
booleanServerResponse
Section titled “ServerResponse”export class ServerResponse {
statusCode: number;
statusMessage: string;
readonly req: IncomingMessage;
readonly headersSent: boolean;
sendDate: boolean;
strictContentLength: boolean;
readonly writable: boolean;
readonly writableEnded: boolean;
readonly writableFinished: boolean;
readonly destroyed: boolean;
constructor(req: IncomingMessage);
writeHead(
statusCode: number,
statusMessage?: string,
headers?: OutgoingHttpHeaders | ReadonlyArray<string>,
): this;
writeHead(
statusCode: number,
headers?: OutgoingHttpHeaders | ReadonlyArray<string>,
): this;
writeContinue(callback?: () => void): void;
writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
writeProcessing(): void;
appendHeader(name: string, value: OutgoingHttpHeader): this;
flushHeaders(): void;
getHeader(name: string): OutgoingHttpHeader | undefined;
getHeaderNames(): string[];
getHeaders(): OutgoingHttpHeaders;
hasHeader(name: string): boolean;
removeHeader(name: string): void;
setHeader(name: string, value: OutgoingHttpHeader): this;
addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<readonly [string, string]>): void;
setTimeout(msecs: number, callback?: () => void): this;
write(chunk: string | Uint8Array, callback?: (error?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (error?: Error | null) => void): boolean;
end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;
end(chunk: string, encoding: string, callback?: () => void): this;
cork(): void;
uncork(): void;
destroy(error?: Error): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
emit(eventName: string | symbol, ...args: any[]): boolean;
}
Writable server response object passed as the second argument to RequestListener.
constructor(req: IncomingMessage);
Construct a ServerResponse bound to req.
| Name | Type | Description |
|---|---|---|
req | IncomingMessage | Associated IncomingMessage. |
| Property | Type | Description | Since |
|---|---|---|---|
statusCode | number | HTTP status code (default 200). | v0.0.0-alpha.2 |
statusMessage | string | HTTP status reason phrase. | v0.0.0-alpha.2 |
req readonly | IncomingMessage | Associated incoming request. | v0.0.0-alpha.2 |
headersSent readonly | boolean | true once response headers have been sent. | v0.0.0-alpha.2 |
sendDate | boolean | Automatically include a Date header (default true). | v0.0.0-alpha.2 |
strictContentLength | boolean | Enforce strict Content-Length byte counting. | v0.0.0-alpha.2 |
writable readonly | boolean | Whether the response stream is writable. | v0.0.0-alpha.2 |
writableEnded readonly | boolean | Whether end() has been called. | v0.0.0-alpha.2 |
writableFinished readonly | boolean | Whether "finish" has been emitted. | v0.0.0-alpha.2 |
destroyed readonly | boolean | Whether destroy() has been called. | v0.0.0-alpha.2 |
ServerResponse.writeHead
Section titled “ServerResponse.writeHead”writeHead(
statusCode: number,
statusMessage?: string,
headers?: OutgoingHttpHeaders | ReadonlyArray<string>,
): this;
writeHead(
statusCode: number,
headers?: OutgoingHttpHeaders | ReadonlyArray<string>,
): this;
Write status code, optional reason message, and response headers.
writeHead(statusCode, statusMessage?, headers?)| Name | Type | Description |
|---|---|---|
statusCode | number | — |
statusMessage optional | string | — |
headers optional | OutgoingHttpHeaders | ReadonlyArray<string> | — |
thiswriteHead(statusCode, headers?)Write status code and response headers.
| Name | Type | Description |
|---|---|---|
statusCode | number | — |
headers optional | OutgoingHttpHeaders | ReadonlyArray<string> | — |
thisServerResponse.writeContinue
Section titled “ServerResponse.writeContinue”writeContinue(callback?: () => void): void;
Send an HTTP 100 Continue interim response.
| Name | Type | Description |
|---|---|---|
callback optional | () => void | — |
voidServerResponse.writeEarlyHints
Section titled “ServerResponse.writeEarlyHints”writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
Send an HTTP 103 Early Hints interim response.
| Name | Type | Description |
|---|---|---|
hints | Record<string, string | string[]> | — |
callback optional | () => void | — |
voidServerResponse.writeProcessing
Section titled “ServerResponse.writeProcessing”writeProcessing(): void;
Send an HTTP 102 Processing interim response.
voidServerResponse.appendHeader
Section titled “ServerResponse.appendHeader”appendHeader(name: string, value: OutgoingHttpHeader): this;
Append value to an existing response header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
value | OutgoingHttpHeader | — |
thisServerResponse.flushHeaders
Section titled “ServerResponse.flushHeaders”flushHeaders(): void;
Flush queued response headers immediately.
voidServerResponse.getHeader
Section titled “ServerResponse.getHeader”getHeader(name: string): OutgoingHttpHeader | undefined;
Retrieve response header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
OutgoingHttpHeader | undefinedServerResponse.getHeaderNames
Section titled “ServerResponse.getHeaderNames”getHeaderNames(): string[];
Return lowercased names of all queued response headers.
string[]ServerResponse.getHeaders
Section titled “ServerResponse.getHeaders”getHeaders(): OutgoingHttpHeaders;
Return a shallow copy of all queued response headers.
ServerResponse.hasHeader
Section titled “ServerResponse.hasHeader”hasHeader(name: string): boolean;
Return true if response header name has been set.
| Name | Type | Description |
|---|---|---|
name | string | — |
booleanServerResponse.removeHeader
Section titled “ServerResponse.removeHeader”removeHeader(name: string): void;
Delete response header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
voidServerResponse.setHeader
Section titled “ServerResponse.setHeader”setHeader(name: string, value: OutgoingHttpHeader): this;
Set or overwrite response header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
value | OutgoingHttpHeader | — |
thisServerResponse.addTrailers
Section titled “ServerResponse.addTrailers”addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<readonly [string, string]>): void;
Add trailing response headers.
| Name | Type | Description |
|---|---|---|
headers | OutgoingHttpHeaders | ReadonlyArray<readonly [string, string]> | — |
voidServerResponse.setTimeout
Section titled “ServerResponse.setTimeout”setTimeout(msecs: number, callback?: () => void): this;
Set socket inactivity timeout in milliseconds.
| Name | Type | Description |
|---|---|---|
msecs | number | — |
callback optional | () => void | — |
thisServerResponse.write
Section titled “ServerResponse.write”write(chunk: string | Uint8Array, callback?: (error?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (error?: Error | null) => void): boolean;
Write a response body chunk.
write(chunk, callback?)| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | — |
callback optional | (error?: Error | null) => void | — |
booleanwrite(chunk, encoding, callback?)Write a response string chunk with explicit encoding.
| Name | Type | Description |
|---|---|---|
chunk | string | — |
encoding | string | — |
callback optional | (error?: Error | null) => void | — |
booleanServerResponse.end
Section titled “ServerResponse.end”end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;
end(chunk: string, encoding: string, callback?: () => void): this;
Finish sending the HTTP response.
end(callback?)| Name | Type | Description |
|---|---|---|
callback optional | () => void | — |
thisend(chunk, callback?)Write a final chunk and finish the HTTP response.
| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | — |
callback optional | () => void | — |
thisend(chunk, encoding, callback?)Write a final string chunk with encoding and finish the HTTP response.
| Name | Type | Description |
|---|---|---|
chunk | string | — |
encoding | string | — |
callback optional | () => void | — |
thisServerResponse.cork
Section titled “ServerResponse.cork”cork(): void;
Buffer subsequent response writes.
voidServerResponse.uncork
Section titled “ServerResponse.uncork”uncork(): void;
Flush buffered response writes.
voidServerResponse.destroy
Section titled “ServerResponse.destroy”destroy(error?: Error): this;
Destroy the response stream.
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisServerResponse.on
Section titled “ServerResponse.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServerResponse.once
Section titled “ServerResponse.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServerResponse.off
Section titled “ServerResponse.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServerResponse.emit
Section titled “ServerResponse.emit”emit(eventName: string | symbol, ...args: any[]): boolean;
Synchronously emit an event.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
...args | any[] | — |
booleanClientRequest
Section titled “ClientRequest”export class ClientRequest {
readonly aborted: boolean;
readonly destroyed: boolean;
readonly method: string;
path: string;
readonly host: string;
readonly protocol: string;
readonly reusedSocket: boolean;
maxHeadersCount: number;
readonly headersSent: boolean;
readonly writable: boolean;
readonly writableEnded: boolean;
readonly writableFinished: boolean;
constructor(
options: string | import("node:url").URL | RequestOptions,
cb?: (res: IncomingMessage) => void,
);
abort(): void;
flushHeaders(): void;
getHeader(name: string): OutgoingHttpHeader | undefined;
getHeaderNames(): string[];
getHeaders(): OutgoingHttpHeaders;
getRawHeaderNames(): string[];
hasHeader(name: string): boolean;
removeHeader(name: string): void;
setHeader(name: string, value: OutgoingHttpHeader): this;
setNoDelay(noDelay?: boolean): void;
setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
setTimeout(timeout: number, callback?: () => void): this;
write(chunk: string | Uint8Array, callback?: (error?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (error?: Error | null) => void): boolean;
end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;
end(chunk: string, encoding: string, callback?: () => void): this;
destroy(error?: Error): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
emit(eventName: string | symbol, ...args: any[]): boolean;
}
Outgoing client HTTP request returned by request() and get().
constructor(
options: string | import("node:url").URL | RequestOptions,
cb?: (res: IncomingMessage) => void,
);
Construct a ClientRequest.
| Name | Type | Description |
|---|---|---|
options | string | import("node:url").URL | RequestOptions | Request URL or options object. |
cb optional | (res: IncomingMessage) => void | Optional "response" event listener. |
| Property | Type | Description | Since |
|---|---|---|---|
aborted readonly | boolean | true if the request has been aborted. | v0.0.0-alpha.2 |
destroyed readonly | boolean | true if destroy() has been called. | v0.0.0-alpha.2 |
method readonly | string | HTTP method string ("GET", "POST", etc.). | v0.0.0-alpha.2 |
path | string | Request path and query string. | v0.0.0-alpha.2 |
host readonly | string | Target host name. | v0.0.0-alpha.2 |
protocol readonly | string | Request protocol scheme ("http:"). | v0.0.0-alpha.2 |
reusedSocket readonly | boolean | true when sent over a reused keep-alive socket. | v0.0.0-alpha.2 |
maxHeadersCount | number | Maximum response header count accepted. | v0.0.0-alpha.2 |
headersSent readonly | boolean | true once request headers have been sent. | v0.0.0-alpha.2 |
writable readonly | boolean | Whether the request stream is writable. | v0.0.0-alpha.2 |
writableEnded readonly | boolean | Whether end() has been called. | v0.0.0-alpha.2 |
writableFinished readonly | boolean | Whether "finish" has been emitted. | v0.0.0-alpha.2 |
ClientRequest.abort
Section titled “ClientRequest.abort”abort(): void;
Abort the in-flight request.
voidClientRequest.flushHeaders
Section titled “ClientRequest.flushHeaders”flushHeaders(): void;
Flush queued request headers immediately.
voidClientRequest.getHeader
Section titled “ClientRequest.getHeader”getHeader(name: string): OutgoingHttpHeader | undefined;
Retrieve request header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
OutgoingHttpHeader | undefinedClientRequest.getHeaderNames
Section titled “ClientRequest.getHeaderNames”getHeaderNames(): string[];
Return lowercased names of all queued request headers.
string[]ClientRequest.getHeaders
Section titled “ClientRequest.getHeaders”getHeaders(): OutgoingHttpHeaders;
Return a shallow copy of all queued request headers.
ClientRequest.getRawHeaderNames
Section titled “ClientRequest.getRawHeaderNames”getRawHeaderNames(): string[];
Return header names in their original casing.
string[]ClientRequest.hasHeader
Section titled “ClientRequest.hasHeader”hasHeader(name: string): boolean;
Return true if request header name is set.
| Name | Type | Description |
|---|---|---|
name | string | — |
booleanClientRequest.removeHeader
Section titled “ClientRequest.removeHeader”removeHeader(name: string): void;
Delete request header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
voidClientRequest.setHeader
Section titled “ClientRequest.setHeader”setHeader(name: string, value: OutgoingHttpHeader): this;
Set or overwrite request header name.
| Name | Type | Description |
|---|---|---|
name | string | — |
value | OutgoingHttpHeader | — |
thisClientRequest.setNoDelay
Section titled “ClientRequest.setNoDelay”setNoDelay(noDelay?: boolean): void;
Configure TCP_NODELAY on the underlying socket.
| Name | Type | Description |
|---|---|---|
noDelay optional | boolean | — |
voidClientRequest.setSocketKeepAlive
Section titled “ClientRequest.setSocketKeepAlive”setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
Configure TCP keep-alive on the underlying socket.
| Name | Type | Description |
|---|---|---|
enable optional | boolean | — |
initialDelay optional | number | — |
voidClientRequest.setTimeout
Section titled “ClientRequest.setTimeout”setTimeout(timeout: number, callback?: () => void): this;
Set inactivity timeout in milliseconds.
| Name | Type | Description |
|---|---|---|
timeout | number | — |
callback optional | () => void | — |
thisClientRequest.write
Section titled “ClientRequest.write”write(chunk: string | Uint8Array, callback?: (error?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (error?: Error | null) => void): boolean;
Write a request body chunk.
write(chunk, callback?)| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | — |
callback optional | (error?: Error | null) => void | — |
booleanwrite(chunk, encoding, callback?)Write a request string chunk with explicit encoding.
| Name | Type | Description |
|---|---|---|
chunk | string | — |
encoding | string | — |
callback optional | (error?: Error | null) => void | — |
booleanClientRequest.end
Section titled “ClientRequest.end”end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;
end(chunk: string, encoding: string, callback?: () => void): this;
Finish sending the HTTP request.
end(callback?)| Name | Type | Description |
|---|---|---|
callback optional | () => void | — |
thisend(chunk, callback?)Write a final chunk and finish sending the HTTP request.
| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | — |
callback optional | () => void | — |
thisend(chunk, encoding, callback?)Write a final string chunk with encoding and finish the HTTP request.
| Name | Type | Description |
|---|---|---|
chunk | string | — |
encoding | string | — |
callback optional | () => void | — |
thisClientRequest.destroy
Section titled “ClientRequest.destroy”destroy(error?: Error): this;
Destroy the request stream.
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisClientRequest.on
Section titled “ClientRequest.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisClientRequest.once
Section titled “ClientRequest.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisClientRequest.off
Section titled “ClientRequest.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisClientRequest.emit
Section titled “ClientRequest.emit”emit(eventName: string | symbol, ...args: any[]): boolean;
Synchronously emit an event.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
...args | any[] | — |
booleanServer
Section titled “Server”export class Server {
readonly listening: boolean;
headersTimeout: number;
keepAliveTimeout: number;
maxHeadersCount: number | null;
maxRequestsPerSocket: number | null;
requestTimeout: number;
timeout: number;
constructor(requestListener?: RequestListener);
constructor(options: ServerOptions, requestListener?: RequestListener);
listen(port?: number, hostname?: string, listeningListener?: () => void): this;
listen(port?: number, listeningListener?: () => void): this;
listen(
options: { port?: number; host?: string; backlog?: number; path?: string },
listeningListener?: () => void,
): this;
close(callback?: (err?: Error) => void): this;
closeAllConnections(): void;
closeIdleConnections(): void;
setTimeout(msecs?: number, callback?: () => void): this;
address(): { address: string; family: string; port: number } | string | null;
ref(): this;
unref(): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
emit(eventName: string | symbol, ...args: any[]): boolean;
[Symbol.asyncDispose](): Promise<void>;
}
HTTP/1.1 server instance returned by createServer().
constructor(requestListener?: RequestListener);
constructor(options: ServerOptions, requestListener?: RequestListener);
Construct an HTTP Server with an optional "request" listener.
new Server(requestListener?)| Name | Type | Description |
|---|---|---|
requestListener optional | RequestListener | Callback invoked for each HTTP request. |
new Server(options, requestListener?)Construct an HTTP Server with explicit options and optional listener.
| Name | Type | Description |
|---|---|---|
options | ServerOptions | Server configuration. |
requestListener optional | RequestListener | Callback invoked for each HTTP request. |
| Property | Type | Description | Since |
|---|---|---|---|
listening readonly | boolean | true while the server is listening for connections. | v0.0.0-alpha.2 |
headersTimeout | number | Maximum milliseconds to wait for incoming headers (default 60000). | v0.0.0-alpha.2 |
keepAliveTimeout | number | Keep-alive timeout in milliseconds (default 5000). | v0.0.0-alpha.2 |
maxHeadersCount | number | null | Maximum number of headers parsed per request. | v0.0.0-alpha.2 |
maxRequestsPerSocket | number | null | Maximum requests handled per keep-alive socket. | v0.0.0-alpha.2 |
requestTimeout | number | Request timeout in milliseconds (default 300000). | v0.0.0-alpha.2 |
timeout | number | Inactivity socket timeout in milliseconds (0 disables). | v0.0.0-alpha.2 |
Server.listen
Section titled “Server.listen”listen(port?: number, hostname?: string, listeningListener?: () => void): this;
listen(port?: number, listeningListener?: () => void): this;
listen(
options: { port?: number; host?: string; backlog?: number; path?: string },
listeningListener?: () => void,
): this;
Start listening for HTTP connections on port.
listen(port?, hostname?, listeningListener?)| Name | Type | Description |
|---|---|---|
port optional | number | — |
hostname optional | string | — |
listeningListener optional | () => void | — |
thislisten(port?, listeningListener?)Start listening on port with optional listener.
| Name | Type | Description |
|---|---|---|
port optional | number | — |
listeningListener optional | () => void | — |
thislisten(options, listeningListener?)Start listening using explicit options.
| Name | Type | Description |
|---|---|---|
options | { port?: number; host?: string; backlog?: number; path?: string } | — |
listeningListener optional | () => void | — |
thisServer.close
Section titled “Server.close”close(callback?: (err?: Error) => void): this;
Stop accepting new connections and close once active requests finish.
| Name | Type | Description |
|---|---|---|
callback optional | (err?: Error) => void | — |
thisServer.closeAllConnections
Section titled “Server.closeAllConnections”closeAllConnections(): void;
Immediately close all connected sockets.
voidServer.closeIdleConnections
Section titled “Server.closeIdleConnections”closeIdleConnections(): void;
Close all idle keep-alive sockets not currently handling a request.
voidServer.setTimeout
Section titled “Server.setTimeout”setTimeout(msecs?: number, callback?: () => void): this;
Set default socket inactivity timeout and optional "timeout" listener.
| Name | Type | Description |
|---|---|---|
msecs optional | number | — |
callback optional | () => void | — |
thisServer.address
Section titled “Server.address”address(): { address: string; family: string; port: number } | string | null;
Return bound local address metadata or null.
{ address: string; family: string; port: number } | string | nullServer.ref
Section titled “Server.ref”ref(): this;
Keep the event loop active while listening.
thisServer.unref
Section titled “Server.unref”unref(): this;
Allow the event loop to exit if the server is the only active handle.
thisServer.on
Section titled “Server.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServer.once
Section titled “Server.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServer.off
Section titled “Server.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServer.emit
Section titled “Server.emit”emit(eventName: string | symbol, ...args: any[]): boolean;
Synchronously emit an event.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
...args | any[] | — |
booleanServer.[Symbol.asyncDispose]
Section titled “Server.[Symbol.asyncDispose]”[Symbol.asyncDispose](): Promise<void>;
Close the server asynchronously when disposed via await using.
Promise<void>Interfaces
Section titled “Interfaces”AbortSignalLike
Section titled “AbortSignalLike”export interface AbortSignalLike {
readonly aborted: boolean;
readonly reason?: unknown;
addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;
removeEventListener?(type: string, listener: (...args: any[]) => void): void;
}
Minimal abort-signal contract accepted by HTTP request and server options.
| Property | Type | Description | Since |
|---|---|---|---|
aborted readonly | boolean | Whether the signal has already been aborted. | v0.0.0-alpha.2 |
reason readonly optional | unknown | Optional abort reason value. | v0.0.0-alpha.2 |
AbortSignalLike.addEventListener
Section titled “AbortSignalLike.addEventListener”addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;
Register an "abort" listener.
| Name | Type | Description |
|---|---|---|
type | string | — |
listener | (...args: any[]) => void | — |
options optional | { once?: boolean } | — |
voidAbortSignalLike.removeEventListener
Section titled “AbortSignalLike.removeEventListener”removeEventListener?(type: string, listener: (...args: any[]) => void): void;
Unregister an "abort" listener.
| Name | Type | Description |
|---|---|---|
type | string | — |
listener | (...args: any[]) => void | — |
voidAgentOptions
Section titled “AgentOptions”export interface AgentOptions {
keepAlive?: boolean;
keepAliveMsecs?: number;
maxSockets?: number;
maxTotalSockets?: number;
maxFreeSockets?: number;
timeout?: number;
scheduling?: "fifo" | "lifo";
}
Options accepted by new Agent(options).
| Property | Type | Description | Since |
|---|---|---|---|
keepAlive optional | boolean | Reuse idle TCP connections across requests (default false). | v0.0.0-alpha.2 |
keepAliveMsecs optional | number | Keep-alive probe initial delay in milliseconds. | v0.0.0-alpha.2 |
maxSockets optional | number | Maximum concurrent sockets per host (default Infinity). | v0.0.0-alpha.2 |
maxTotalSockets optional | number | Maximum total concurrent sockets across all hosts. | v0.0.0-alpha.2 |
maxFreeSockets optional | number | Maximum idle sockets kept open per host when keepAlive is enabled. | v0.0.0-alpha.2 |
timeout optional | number | Default socket timeout in milliseconds. | v0.0.0-alpha.2 |
scheduling optional | "fifo" | "lifo" | Scheduling strategy for idle socket reuse ("fifo" or "lifo"). | v0.0.0-alpha.2 |
RequestOptions
Section titled “RequestOptions”export interface RequestOptions {
protocol?: string | null;
host?: string | null;
hostname?: string | null;
family?: number;
port?: number | string | null;
localAddress?: string;
socketPath?: string;
method?: string;
path?: string | null;
headers?: OutgoingHttpHeaders;
auth?: string | null;
agent?: Agent | boolean;
timeout?: number;
signal?: AbortSignalLike;
setHost?: boolean;
}
Options accepted by request(), get(), and new ClientRequest().
| Property | Type | Description | Since |
|---|---|---|---|
protocol optional | string | null | URL protocol scheme ("http:"). | v0.0.0-alpha.2 |
host optional | string | null | Target host or IP address. | v0.0.0-alpha.2 |
hostname optional | string | null | Target hostname (preferred over host). | v0.0.0-alpha.2 |
family optional | number | IP address family (4 or 6). | v0.0.0-alpha.2 |
port optional | number | string | null | Target TCP port. | v0.0.0-alpha.2 |
localAddress optional | string | Local interface IP to bind for outgoing sockets. | v0.0.0-alpha.2 |
socketPath optional | string | Unix domain socket path. | v0.0.0-alpha.2 |
method optional | string | HTTP method ("GET", "POST", etc.). | v0.0.0-alpha.2 |
path optional | string | null | Request path and query string (default "/"). | v0.0.0-alpha.2 |
headers optional | OutgoingHttpHeaders | Outgoing HTTP headers. | v0.0.0-alpha.2 |
auth optional | string | null | Basic authentication "user:password" string. | v0.0.0-alpha.2 |
agent optional | Agent | boolean | Connection-pooling Agent, or false to bypass pooling. | v0.0.0-alpha.2 |
timeout optional | number | Socket inactivity timeout in milliseconds. | v0.0.0-alpha.2 |
signal optional | AbortSignalLike | Optional abort signal cancelling the in-flight request. | v0.0.0-alpha.2 |
setHost optional | boolean | Set the Host header automatically (default true). | v0.0.0-alpha.2 |
ServerOptions
Section titled “ServerOptions”export interface ServerOptions {
IncomingMessage?: typeof IncomingMessage;
ServerResponse?: typeof ServerResponse;
keepAliveTimeout?: number;
headersTimeout?: number;
requestTimeout?: number;
maxHeaderSize?: number;
requireHostHeader?: boolean;
noDelay?: boolean;
keepAlive?: boolean;
keepAliveInitialDelay?: number;
}
Options accepted by createServer() and new Server().
| Property | Type | Description | Since |
|---|---|---|---|
IncomingMessage optional | typeof IncomingMessage | Custom IncomingMessage subclass constructor. | v0.0.0-alpha.2 |
ServerResponse optional | typeof ServerResponse | Custom ServerResponse subclass constructor. | v0.0.0-alpha.2 |
keepAliveTimeout optional | number | Keep-alive idle socket timeout in milliseconds (default 5000). | v0.0.0-alpha.2 |
headersTimeout optional | number | Maximum milliseconds to receive complete request headers. | v0.0.0-alpha.2 |
requestTimeout optional | number | Maximum milliseconds for an entire incoming request. | v0.0.0-alpha.2 |
maxHeaderSize optional | number | Maximum HTTP header block size in bytes. | v0.0.0-alpha.2 |
requireHostHeader optional | boolean | Reject requests missing a Host header on HTTP/1.1. | v0.0.0-alpha.2 |
noDelay optional | boolean | Disable Nagle's algorithm (TCP_NODELAY). | v0.0.0-alpha.2 |
keepAlive optional | boolean | Enable TCP keep-alive probes. | v0.0.0-alpha.2 |
keepAliveInitialDelay optional | number | Initial TCP keep-alive delay in milliseconds. | v0.0.0-alpha.2 |
Type Aliases
Section titled “Type Aliases”IncomingHttpHeaders
Section titled “IncomingHttpHeaders”export type IncomingHttpHeaders = Record<string, string | string[] | undefined>;
Parsed HTTP header map for incoming requests and responses.
OutgoingHttpHeader
Section titled “OutgoingHttpHeader”export type OutgoingHttpHeader = number | string | readonly string[];
Value accepted for an outgoing HTTP header.
OutgoingHttpHeaders
Section titled “OutgoingHttpHeaders”export type OutgoingHttpHeaders = Record<string, OutgoingHttpHeader | undefined>;
Outgoing HTTP header dictionary keyed by header name.
RequestListener
Section titled “RequestListener”export type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
Callback invoked for each incoming HTTP request on a Server.
Constants
Section titled “Constants”METHODS
Section titled “METHODS”export const METHODS: readonly string[];
List of HTTP methods supported by the HTTP parser, sorted alphabetically.
STATUS_CODES
Section titled “STATUS_CODES”export const STATUS_CODES: Record<number | string, string | undefined>;
Mapping from HTTP status codes (for example 200, 404) to standard
reason phrases (for example "OK", "Not Found").
globalAgent
Section titled “globalAgent”export const globalAgent: Agent;
Default global HTTP Agent used when no custom agent is supplied.
maxHeaderSize
Section titled “maxHeaderSize”export const maxHeaderSize: number;
Maximum HTTP header block size in bytes (default 16384).
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: {
/** `Agent` constructor. @since 0.0.0-alpha.2 */
Agent: typeof Agent;
/** `ClientRequest` constructor. @since 0.0.0-alpha.2 */
ClientRequest: typeof ClientRequest;
/** `IncomingMessage` constructor. @since 0.0.0-alpha.2 */
IncomingMessage: typeof IncomingMessage;
/** Supported HTTP methods list. @since 0.0.0-alpha.2 */
readonly METHODS: readonly string[];
/** `OutgoingMessage` constructor. @since 0.0.0-alpha.2 */
OutgoingMessage: typeof OutgoingMessage;
/** HTTP status code reason phrases map. @since 0.0.0-alpha.2 */
readonly STATUS_CODES: Record<number | string, string | undefined>;
/** `Server` constructor. @since 0.0.0-alpha.2 */
Server: typeof Server;
/** `ServerResponse` constructor. @since 0.0.0-alpha.2 */
ServerResponse: typeof ServerResponse;
/** Create an HTTP server. @since 0.0.0-alpha.2 */
createServer: typeof createServer;
/** Issue a GET request. @since 0.0.0-alpha.2 */
get: typeof get;
/** Default global HTTP `Agent`. @since 0.0.0-alpha.2 */
readonly globalAgent: Agent;
/** Default max HTTP header size in bytes. @since 0.0.0-alpha.2 */
readonly maxHeaderSize: number;
/** Issue an HTTP request. @since 0.0.0-alpha.2 */
request: typeof request;
/** Validate an HTTP header name. @since 0.0.0-alpha.2 */
validateHeaderName: typeof validateHeaderName;
/** Validate an HTTP header value. @since 0.0.0-alpha.2 */
validateHeaderValue: typeof validateHeaderValue;
};
export default _default;
Default export object providing the node:http API.
