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 🙏

© 2025 – Pkg Stats / Ryan Hefner

proxy-protocol-js

v4.0.6

Published

A PROXY protocol builder and parser for JavaScript

Downloads

9,303

Readme

proxy-protocol-js CircleCI codecov NPM

A PROXY protocol builder and parser for JavaScript.

Features

  • Supports the features
    • building PROXY protocol payload
    • parsing PROXY protocol payload
    • identifying the PROXY protocol version
  • Supports both of the version: V1 and V2 protocol
  • Also supports TypeScript
  • It doesn't requre the extra dependencies

Usage

See also examples and TSDoc.

Build (and identity the protocol version)

V1 protocol

const proxyProtocol = require('proxy-protocol-js');

const src = new proxyProtocol.Peer('127.0.0.1', 12345);
const dst = new proxyProtocol.Peer('192.0.2.1', 54321);
const protocolText = new proxyProtocol.V1ProxyProtocol(
  proxyProtocol.INETProtocol.TCP4,
  src,
  dst,
).build();
console.log(protocolText); // => PROXY TCP4 127.0.0.1 192.0.2.1 12345 54321\r\n

const identifiedProtocolVersion = proxyProtocol.ProxyProtocolIdentifier.identify(protocolText);
console.log(identifiedProtocolVersion); // => proxyProtocol.ProxyProtocolVersion.V1 (= 0xx10)

V2 protocol

const proxyProtocol = require('proxy-protocol-js');

const proto = new proxyProtocol.V2ProxyProtocol(
  proxyProtocol.Command.LOCAL,
  proxyProtocol.TransportProtocol.DGRAM,
  new proxyProtocol.IPv4ProxyAddress(
    proxyProtocol.IPv4Address.createFrom([127, 0, 0, 1]),
    12345,
    proxyProtocol.IPv4Address.createFrom([192, 0, 2, 1]),
    54321,
  ),
).build();
console.log(proto);

const identifiedProtocolVersion = proxyProtocol.ProxyProtocolIdentifier.identify(proto);
console.log(identifiedProtocolVersion); // => proxyProtocol.ProxyProtocolVersion.V2 (= 0x20)

Parse

V1 protocol

const proxyProtocol = require('proxy-protocol');

const protocolText = 'PROXY TCP4 127.0.0.1 192.0.2.1 12345 54321\r\n';
const proto = proxyProtocol.V1ProxyProtocol.parse(protocolText);
console.log(proto);
// => V1ProxyProtocol {
//      inetProtocol: 'TCP4',
//      source: Host { ipAddress: '127.0.0.1', port: 12345 },
//      destination: Host { ipAddress: '192.0.2.1', port: 54321 },
//      data: '' }

V2 protocol

const proxyProtocol = require('proxy-protocol-js');

const protoBin = new Uint8Array([13, 10, 13, 10, 0, 13, 10, 81, 85, 73, 84, 10, 32, 18, 0, 12, 127, 0, 0, 1, 192, 0, 2, 1, 48, 57, 212, 49]);
const proto = proxyProtocol.V2ProxyProtocol.parse(protoBin);
console.log(proto);
// => V2ProxyProtocol {
//   command: 0,
//   transportProtocol: 2,
//   proxyAddress:
//    IPv4ProxyAddress {
//      sourceAddress: IPv4Address { address: [Array] },
//      sourcePort: 12345,
//      destinationAddress: IPv4Address { address: [Array] },
//      destinationPort: 54321 },
//   data: Uint8Array [],
//   addressFamilyType: 16 }`

Performance

The result of the comparison between this library (proxy-protocol-js) and proxy-protocol is here:

proxy-protocol.parse x 246,423 ops/sec ±3.10% (32 runs sampled)
proxy-protocol-js.parse x 481,388 ops/sec ±5.32% (69 runs sampled)
Fastest is proxy-protocol-js.parse

(moreover, proxy-protocol-js's benchmark contains unnecessary dummy codes for fairness)

This benchmark run on the node v10.15.3 and the code is here.

Author

moznion ([email protected])

License

MIT