npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bare-tls

v3.1.5

Published

Transport Layer Security (TLS) streams for JavaScript

Readme

bare-tls

Transport Layer Security (TLS) streams for JavaScript, built on BoringSSL. Provides both a low-level Socket class that wraps any duplex stream with TLS and higher-level createServer() and connect() functions for TLS over TCP, similar to node:tls. Mozilla root certificates are bundled for out-of-the-box certificate verification.

npm i bare-tls

Usage

const tls = require('bare-tls')
const fs = require('bare-fs')

const server = tls.createServer(
  {
    cert: fs.readFileSync('cert.pem'),
    key: fs.readFileSync('key.pem')
  },
  (socket) => {
    socket.on('data', (data) => socket.end('pong')).on('close', () => server.close())
  }
)

server.listen(8443)

const client = tls.connect({ port: 8443, host: 'localhost' })

client.on('data', (data) => console.log(data)).end('ping')

API

const socket = new tls.Socket(stream[, options])

Wraps an existing duplex stream with TLS. The underlying stream handles transport; the TLS socket handles encryption and decryption.

Options include:

options = {
  isServer: false,
  cert: null,
  key: null,
  host: null,
  rejectUnauthorized: true,
  ca: null,
  alpnProtocols: null,
  eagerOpen: true,
  allowHalfOpen: true,
  readBufferSize: 65536
}

isServer controls whether the socket acts as a TLS server or client. If true, cert and key must be provided.

cert and key are Buffers containing PEM-encoded certificate and private key data, respectively.

host enables hostname verification against the server certificate. For DNS names it is also sent as the SNI (Server Name Indication) extension; for IP literals it is matched against the certificate's IP SANs and SNI is suppressed per RFC 6066. Required for client sockets unless rejectUnauthorized is false.

rejectUnauthorized controls whether the client rejects connections when certificate verification fails. Defaults to true.

ca is a Buffer containing one or more PEM-encoded CA certificates. When provided, only these CAs are used for verification instead of the bundled Mozilla root certificates.

alpnProtocols is an array of ALPN protocol name strings, ordered by preference.

socket.socket

The underlying duplex stream.

socket.encrypted

Always true.

socket.alpnProtocol

The negotiated ALPN protocol as a string, or null if no protocol was negotiated.

event: 'connect'

Emitted when the TLS handshake completes.

const server = tls.createServer([options][, onconnection])

Creates a TLS server that listens for TCP connections and wraps them with TLS. Incoming connections are emitted as 'connection' events with a tls.Socket instance. Options are the same as tls.Socket, plus any options supported by https://github.com/holepunchto/bare-net.

server.listen(...args)

Start listening for connections. Arguments are passed through to the underlying TCP server.

server.close([onclose])

Stop listening for connections.

server.address()

Returns the bound address of the server.

server.listening

Whether or not the server is listening.

server.ref()

Ref the server.

server.unref()

Unref the server.

event: 'listening'

Emitted when the server starts listening.

event: 'connection'

Emitted when a new TLS connection is established.

event: 'close'

Emitted when the server closes.

event: 'error'

Emitted on server error.

const socket = tls.connect(options[, onconnect])

Creates a TCP connection and wraps it with TLS. options are passed to both the underlying TCP socket and tls.Socket. At minimum, port must be specified. host is used for both the TCP connection target and TLS hostname verification, and defaults to 'localhost'.

const socket = tls.connect(port[, host][, onconnect])

Shorthand for tls.connect({ port, host }).

License

Apache-2.0