Skip to main content
createSecureServer - http2 - Node documentation
function createSecureServer

Usage in Deno

import { createSecureServer } from "node:http2";
createSecureServer(onRequestHandler?: () => void): Http2SecureServer

Returns a tls.Server instance that creates and manages Http2Session instances.

import http2 from 'node:http2';
import fs from 'node:fs';

const options = {
  key: fs.readFileSync('server-key.pem'),
  cert: fs.readFileSync('server-cert.pem'),
};

// Create a secure HTTP/2 server
const server = http2.createSecureServer(options);

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

server.listen(8443);

Parameters

optional
onRequestHandler: () => void

See Compatibility API

Return Type

createSecureServer<
Http1Request extends IncomingMessage = IncomingMessage,
Http1Response extends ServerResponse = ServerResponse,
Http2Request extends Http2ServerRequest = Http2ServerRequest,
Http2Response extends Http2ServerResponse = Http2ServerResponse,
>
(
options: SecureServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
onRequestHandler?: (
request: InstanceType<Http2Request>,
response: InstanceType<Http2Response>,
) => void
,
): Http2SecureServer<Http1Request, Http1Response, Http2Request, Http2Response>

Type Parameters

Http1Request extends IncomingMessage = IncomingMessage
Http1Response extends ServerResponse = ServerResponse
Http2Request extends Http2ServerRequest = Http2ServerRequest
Http2Response extends Http2ServerResponse = Http2ServerResponse

Parameters

optional
onRequestHandler: (
request: InstanceType<Http2Request>,
response: InstanceType<Http2Response>,
) => void

Return Type

Back to top