Skip to main content
createServer - node__tls.d.ts - Node documentation
function createServer

Usage in Deno

```typescript import { createServer } from "node:node__tls.d.ts"; ```
createServer(secureConnectionListener?: (socket: TLSSocket) => void): Server
Creates a new [Server](../.././node__tls.d.ts/~/Server). The `secureConnectionListener`, if provided, is automatically set as a listener for the `'secureConnection'` event. The `ticketKeys` options is automatically shared between `node:cluster` module workers. The following illustrates a simple echo server: ```js import tls from 'node:tls'; import fs from 'node:fs'; const options = { key: fs.readFileSync('server-key.pem'), cert: fs.readFileSync('server-cert.pem'), // This is necessary only if using client certificate authentication. requestCert: true, // This is necessary only if the client uses a self-signed certificate. ca: [ fs.readFileSync('client-cert.pem') ], }; const server = tls.createServer(options, (socket) => { console.log('server connected', socket.authorized ? 'authorized' : 'unauthorized'); socket.write('welcome!\n'); socket.setEncoding('utf8'); socket.pipe(socket); }); server.listen(8000, () => { console.log('server bound'); }); ``` The server can be tested by connecting to it using the example client from [connect](../.././node__tls.d.ts/~/connect).

Parameters

optional
secureConnectionListener: (socket: TLSSocket) => void

Return Type

createServer(
options: TlsOptions,
secureConnectionListener?: (socket: TLSSocket) => void,
): Server

Parameters

options: TlsOptions
optional
secureConnectionListener: (socket: TLSSocket) => void

Return Type