createServer - Node documentation
function createServer

Usage in Deno

import { createServer } from "node:https";
createServer<
Request extends http.IncomingMessage = http.IncomingMessage,
Response extends http.ServerResponse = http.ServerResponse,
>
(requestListener?: http.RequestListener<Request, Response>): Server<Request, Response>
// curl -k https://localhost:8000/
const https = require('node:https');
const fs = require('node:fs');

const options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
};

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(8000);

Or

const https = require('node:https');
const fs = require('node:fs');

const options = {
  pfx: fs.readFileSync('test/fixtures/test_cert.pfx'),
  passphrase: 'sample',
};

https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(8000);

Type Parameters

Request extends http.IncomingMessage = http.IncomingMessage
Response extends http.ServerResponse = http.ServerResponse

Parameters

optional
requestListener: http.RequestListener<Request, Response>

A listener to be added to the 'request' event.

Return Type

createServer<
Request extends http.IncomingMessage = http.IncomingMessage,
Response extends http.ServerResponse = http.ServerResponse,
>
(
options: ServerOptions<Request, Response>,
requestListener?: http.RequestListener<Request, Response>,
): Server<Request, Response>

Type Parameters

Request extends http.IncomingMessage = http.IncomingMessage
Response extends http.ServerResponse = http.ServerResponse

Parameters

optional
requestListener: http.RequestListener<Request, Response>

Return Type