node:http provides Node’s HTTP/1.1 server and client; node:https provides the
client only. For a Fetch-style handler or HTTP/2, use Elide.serve.
Example
// http.mjs
import { createServer } from "node:http";
const server = createServer((req, res) => {
res.writeHead(200, { "content-type": "text/plain" });
res.end(`${req.method} ${req.url}\n`);
});
server.listen(0, "127.0.0.1", async () => {
const { port } = server.address();
const response = await fetch(`http://127.0.0.1:${port}/hello`);
console.log(response.status, response.headers.get("content-type"));
console.log(await response.text());
server.close();
});elide run http.mjs prints:
200 text/plain
GET /helloDifferences from Node
https.createServerthrowsERR_HTTPS_SERVER_UNSUPPORTED; terminate TLS in front ofhttp.createServer.http.globalAgentdefaults tokeepAlive: true,maxSockets: Infinity, andmaxFreeSockets: 256.- HTTPS certificate validation follows fetch.
node:http2is unavailable.--allow-netand--deny-netapply under the sandbox.
Samples
Reference
Status: Partial · Not measured
http exports
Agent, ClientRequest, IncomingMessage, OutgoingMessage, Server, ServerResponse, createServer, get, globalAgent, maxHeaderSize, request, setMaxIdleHTTPParsers, validateHeaderName, validateHeaderValue, 2 constants such as METHODS
Not implemented
CloseEvent, MessageEvent, WebSocket, setGlobalProxyFromEnv.