Skip to main content
createServer - https - 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/
import https from 'node:https';
import fs from '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

import https from 'node:https';
import fs from '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