# resolve-alpn

> Detects the ALPN protocol

Latest version **1.2.1** (published 2021-08-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install resolve-alpn
pnpm add resolve-alpn
yarn add resolve-alpn
bun add resolve-alpn
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2021-08-30 |
| First published | 2018-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Szymon Marczak |
| Maintainers | szmarczak |
| Keywords | alpn, tls, socket, http2 |

## Links

- npm: https://www.npmjs.com/package/resolve-alpn
- Repository: https://github.com/szmarczak/resolve-alpn
- Homepage: https://github.com/szmarczak/resolve-alpn#readme
- Issues: https://github.com/szmarczak/resolve-alpn/issues
- npm.io page: https://npm.io/package/resolve-alpn

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2021-08-30
- 1.2.0 — 2021-07-21
- 1.1.2 — 2021-04-15
- 1.1.1 — 2021-04-11
- 1.1.0 — 2021-04-11
- 1.0.1 — 2021-04-11
- 1.0.0 — 2018-12-23

## README

# `resolve-alpn`

[![Node CI](https://github.com/szmarczak/resolve-alpn/workflows/Node%20CI/badge.svg)](https://github.com/szmarczak/resolve-alpn/actions)
[![codecov](https://codecov.io/gh/szmarczak/resolve-alpn/branch/master/graph/badge.svg)](https://codecov.io/gh/szmarczak/resolve-alpn)

## API

### resolveALPN(options, connect = tls.connect)

Returns an object with an `alpnProtocol` property. The `socket` property may be also present.

```js
const result = await resolveALPN({
	host: 'nghttp2.org',
	port: 443,
	ALPNProtocols: ['h2', 'http/1.1'],
	servername: 'nghttp2.org'
});

console.log(result); // {alpnProtocol: 'h2'}
```

**Note:** While the `servername` option is not required in this case, many other servers do. It's best practice to set it anyway.

**Note:** If the socket times out, the promise will resolve and `result.timeout` will be set to `true`.

#### options

Same as [TLS options](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback).

##### options.resolveSocket

By default, the socket gets destroyed and the promise resolves.<br>
If you set this to true, it will return the socket in a `socket` property.

```js
const result = await resolveALPN({
	host: 'nghttp2.org',
	port: 443,
	ALPNProtocols: ['h2', 'http/1.1'],
	servername: 'nghttp2.org',
	resolveSocket: true
});

console.log(result); // {alpnProtocol: 'h2', socket: tls.TLSSocket}

// Remember to destroy the socket if you don't use it!
result.socket.destroy();
```

#### connect

Type: `Function<TLSSocket> | AsyncFunction<TLSSocket>`\
Default: [`tls.connect`](https://nodejs.org/dist/latest-v16.x/docs/api/tls.html#tls_tls_connect_options_callback)

**Note:** No matter which function is used (synchronous or asynchronous), it **must** accept a `callback` function as a second argument. The `callback` function gets executed when the socket has successfully connected.

## License

MIT

---
_Source: https://npm.io/package/resolve-alpn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
