HTTP

Target host name. @compat elide Full

Module: node:http Support: Experimental

7 members: 2 supported, 5 undocumented

Static Methods

🟢 createServer(options, requestListener)
Creates and returns a new HTTP Server.
⚪ request(options, callback)
Timeout in milliseconds before response headers must be sent. @compat elide Full
🟢 get(options, callback)
Convenience method that issues a GET request and calls end() automatically.

Properties

⚪ METHODS
All supported HTTP methods as an array of strings. @compat elide Full
⚪ STATUS_CODES
Map of HTTP status codes to their standard reason phrases. @compat elide Full
⚪ globalAgent
The global HTTP agent used for connection pooling. @compat elide Full
⚪ maxHeaderSize
Maximum allowed HTTP header size in bytes.

Dictionary ServerOptions

Options for creating an HTTP server.

Since: 1.1.0 Docs: Node.js Docs

3 members: 3 undocumented

Properties

⚪ insecureHTTPParser
Allow non-standard HTTP parsing (relaxed header validation).
⚪ maxHeaderSize
Maximum allowed HTTP header size in bytes.
⚪ joinDuplicateHeaders
If true, duplicate header fields are joined with a comma.

---

Interface Server

An HTTP server that listens for incoming connections. Created via http.createServer(); extends EventEmitter for connection/request events.

Extends: NetServer Implements: EventEmitter Since: 1.1.0 Docs: Node.js Docs

15 members: 7 supported, 8 undocumented

Methods

🟢 close(callback)
Stops the server from accepting new connections.
🟢 listen(port, hostname, backlog, callback)
Begins accepting connections on the specified port and host.
🟢 setTimeout(msecs, callback)
Sets the socket timeout for this server.
⚪ closeAllConnections()
Destroys all open connections, including keep-alive connections. @compat elide Full
⚪ closeIdleConnections()
Destroys all idle (keep-alive) connections that have no pending requests. @compat elide Full
🟢 ref()
Keeps the event loop alive as long as this server is listening.
🟢 unref()
Allows the event loop to exit even if this server is still listening.
🟢 getConnections(callback)
Returns the number of currently open connections.

Properties

🟢 listening
Begins accepting connections on the specified port and host.
⚪ maxConnections
Maximum number of simultaneous connections allowed. @compat elide Full
⚪ maxRequestsPerSocket
Maximum requests per socket before the socket is closed. @compat elide Full
⚪ headersTimeout
Timeout in milliseconds before response headers must be sent. @compat elide Full
⚪ requestTimeout
Timeout in milliseconds for each incoming request. @compat elide Full
⚪ timeout
Timeout in milliseconds for each incoming request. @compat elide Full
⚪ keepAliveTimeout
Keep-alive socket timeout in milliseconds. @compat elide Full

---

Interface IncomingMessage

Represents an incoming HTTP message (request on a server, or response on a client).

Extends: Readable Implements: EventEmitter Since: 1.1.0 Docs: Node.js Docs

18 members: 2 supported, 16 undocumented

Methods

🟢 setTimeout(msecs, callback)
Sets the socket timeout for this server.
🟢 destroy(error)
Destroys the underlying socket.

Properties

⚪ complete
True if the message has been fully received. @compat elide Full
⚪ aborted
True if the message has been fully received. @compat elide Full
⚪ headers
Maximum requests per socket before the socket is closed. @compat elide Full
⚪ headersDistinct
Header fields grouped into arrays by name. @compat elide Full
⚪ rawHeaders
Raw header names and values as alternating strings in the original order. @compat elide Full
⚪ trailers
Parsed trailer fields (populated after the message body). @compat elide Full
⚪ trailersDistinct
Trailer fields grouped into arrays by name. @compat elide Full
⚪ rawTrailers
Raw trailer names and values. @compat elide Full
⚪ httpVersion
Full HTTP version string (e.g. "1.1"). @compat elide Full
⚪ httpVersionMajor
Major HTTP version number. @compat elide Full
⚪ httpVersionMinor
Minor HTTP version number. @compat elide Full
⚪ method
Minor HTTP version number. @compat elide Full
⚪ url
Request URL string (only set on server-side requests). @compat elide Full
⚪ statusCode
Response status code (only set on client-side responses). @compat elide Full
⚪ statusMessage
Response status message (only set on client-side responses). @compat elide Full
⚪ socket
Maximum number of simultaneous connections allowed. @compat elide Full

---

Interface ServerResponse

Writable HTTP server response sent back to the client.

Extends: Writable Implements: EventEmitter Since: 1.1.0 Docs: Node.js Docs

21 members: 13 supported, 8 undocumented

Methods

🟢 writeHead(statusCode, statusMessage, headers)
Sends the response status line and headers.
🟢 setHeader(name, value)
Sets a single response header field, replacing any existing value.
🟢 getHeader(name)
Returns the value of a previously set response header.
🟢 getHeaderNames()
Returns the names of all response headers that have been set.
🟢 getHeaders()
Returns a shallow copy of all currently set response headers.
🟢 hasHeader(name)
Returns true if the named response header has been set.
🟢 removeHeader(name)
Removes a response header that was previously set.
🟢 write(chunk, encoding, callback)
Sends a chunk of the response body.
🟢 end(data, encoding, callback)
Signals that all response body data has been sent.
🟢 addTrailers(headers)
Adds HTTP trailing headers after the response body.
⚪ writeContinue()
Sends an HTTP 100 Continue response (for Expect: 100-continue requests). @compat elide Full
⚪ writeProcessing()
Sends an HTTP 102 Processing response. @compat elide Full
🟢 setTimeout(msecs, callback)
Sets the socket timeout for this server.
🟢 destroy(error)
Destroys the underlying socket.
🟢 flushHeaders()
Flushes the response headers if they have not been sent yet.

Properties

⚪ statusCode
Response status code (only set on client-side responses). @compat elide Full
⚪ statusMessage
Response status message (only set on client-side responses). @compat elide Full
⚪ headersSent
True if response headers have already been flushed to the client. @compat elide Full
⚪ socket
Maximum number of simultaneous connections allowed. @compat elide Full
⚪ writableEnded
True if end() has been called. @compat elide Full
⚪ writableFinished
True if the response has been fully flushed to the kernel. @compat elide Full

---

Interface ClientRequest

An outgoing HTTP request made by the client.

Extends: Writable Implements: EventEmitter Since: 1.1.0 Docs: Node.js Docs

15 members: 10 supported, 5 undocumented

Methods

🟢 setHeader(name, value)
Sets a single response header field, replacing any existing value.
🟢 getHeader(name)
Returns the value of a previously set response header.
🟢 removeHeader(name)
Removes a response header that was previously set.
🟢 write(chunk, encoding, callback)
Sends a chunk of the response body.
🟢 end(data, encoding, callback)
Signals that all response body data has been sent.
🟢 abort()
Aborts the request.
🟢 destroy(error)
Destroys the underlying socket.
🟢 setTimeout(timeout, callback)
Sets the socket timeout for this server.
🟢 setNoDelay(noDelay)
Disables the Nagle algorithm on the socket.
🟢 setSocketKeepAlive(enable, initialDelay)
Enables TCP keep-alive on the socket.

Properties

⚪ method
Minor HTTP version number. @compat elide Full
⚪ path
HTTP method for this request. @compat elide Full
⚪ host
Request path including query string. @compat elide Full
⚪ protocol
Protocol (e.g. "http:"). @compat elide Full
⚪ reusedSocket
True if the request reused a keep-alive socket. @compat elide Full

---

Details

abort()

abort()

abort()

Aborts the request.

> Known issue: Deprecated since Node.js v14.1.0; use destroy() instead

---