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 🙏

© 2024 – Pkg Stats / Ryan Hefner

towing-hook

v0.0.9

Published

Tunnel all outgoing TCP connections in your application through WebSockets

Downloads

13

Readme

towing-hook

Route your Node.js application's TCP connectivity through WebSockets. Built on tcp-over-websockets.

Useful for scenarios where you are unable to make socket connections, eg:

  • You are behind a corporate firewall that only allows outbound http(s) traffic

  • If you are using StackBlitz, which runs Node.js completely within the browser, and hence does not support socket connections

See an example of this here.

Quickstart

Out-of-the-box, this package will route connections through a tunnel service maintained by the package author. You may wish to set-up your own tunnel service by following the instructions below.

Setting up a self-hosted tunnel service

Use npx to run a tcp-over-websockets tunnel service. This will accept your websocket connection and make a socket connection on your behalf:

$ DEBUG=tcp-over-websockets:* npx -p tcp-over-websockets tcp-over-websockets-server
listening on 8080

As a module hook

# By default, connections go through wss://towing-service.fly.dev.
# This is maintained by the package author.
# If you prefer to use another tunnel service, set this env var:
$ export TOW_TUNNEL=ws://localhost:8080

# You may wish to enable debug logging for the underlying
# tcp-over-websockets dependency by setting this env var
$ export DEBUG=tcp-over-websockets:*

# Use towing-hook without modifying your application
$ node -r towing-hook/register your-application.js

Programmatic use

const { hookToTunnel } = require('towing-hook')

hookToTunnel('ws://localhost:8080')

// Connections are now routed through websockets

How it works

This package glues two dependencies together, mitm.js and tcp-over-websockets.

When invoked, mitm.js will intercept most calls to create connections, in particular net.connect() and tls.connect(). towing-hook will then attach the sockets created by mitm.js to tcp-over-websockets, which will route data from those sockets over a websocket connection.

mitm.js creates mock sockets that behave like raw socket connections, notably for sockets created using tls.connect(). TLS support is hence grafted on using Forge.

Gotchas

Sockets created manually are not intercepted

mitm.js does not intercept connections made with net.Socket#connect() or tls.Socket#connect(), as it does not stub the Socket constructor in the net module. If your application or dependency uses this for connectivity, towing-hook will not route your connection.

ie, the following will not work:

const net = require('net')
const socket = new net.Socket()

socket.connect(22, 'example.org')

but the following will:

const net = require('net')
const socket = net.connect(22, 'example.org')

Track moll/node-mitm#42 for progress on this issue.