createServer - Node documentation
function createServer

Usage

import { createServer } from "node:http2";

Returns a net.Server instance that creates and manages Http2Sessioninstances.

Since there are no browsers known that support unencrypted HTTP/2, the use of createSecureServer is necessary when communicating with browser clients.

const http2 = require('node:http2');

// Create an unencrypted HTTP/2 server.
// Since there are no browsers known that support
// unencrypted HTTP/2, the use of `http2.createSecureServer()`
// is necessary when communicating with browser clients.
const server = http2.createServer();

server.on('stream', (stream, headers) => {
  stream.respond({
    'content-type': 'text/html; charset=utf-8',
    ':status': 200,
  });
  stream.end('<h1>Hello World</h1>');
});

server.listen(8000);

Parameters

optional
onRequestHandler: (request: Http2ServerRequest, response: Http2ServerResponse) => void

See Compatibility API

Return Type

Parameters

options: ServerOptions
optional
onRequestHandler: (request: Http2ServerRequest, response: Http2ServerResponse) => void

Return Type