Inherited from v1.0.0

tls module

Same surface as net but wrapped in OpenSSL. Used internally by web for HTTPS and by request for HTTPS clients — usually you reach for those higher-level modules instead.

import "tls" as tls;

var server = tls.listen(8443, {
    cert: io.read_file("server.crt"),
    key:  io.read_file("server.key")
}, function (conn) {
    conn.on_data(function (chunk) { conn.write("got " + chunk); });
});

API

FunctionDescription
tls.listen(port, opts, on_conn) → serverTLS server. opts.cert / opts.key are PEM strings. Returns {port, close()}.
tls.connect(host, port, opts, on_conn)TLS client. opts.servername for SNI; pass {} for defaults. on_conn(err, conn).

Connection object

Same shape as net:

  • conn.write(data, cb?)
  • conn.on_data(fn)
  • conn.on_end(fn)
  • conn.close()

See also

  • net — plain TCP.
  • web — HTTPS server framework.
  • request — HTTPS client.