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
| Function | Description |
|---|---|
tls.listen(port, opts, on_conn) → server | TLS 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()