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

tuna-for-node

v0.2.1

Published

Nodejs wrapper around NKN Tuna

Downloads

10

Readme

Nodejs wrapper around NKN Tuna

Allows using NKN tuna directly from a nodejs script.

Example:

import { startTuna, waitConnected } from 'tuna-for-node'

//starts the tuna process
await startTuna('entry', new URL('./config/', import.meta.url))

//awaits tuna is connected
const ip = await waitConnected()
console.log('IP:', ip)

Installation

requires node 20 or greater

npm

npm install tuna-for-node

pnpm

pnpm add tuna-for-node

What it does

It downloads the correct tuna release binary (based on the platform) from Tuna releases. And uses a simple script to start/stop the process (using spawn).

API

startTuna ⇒ Promise<void>

Starts the tuna client.

| Param | Type | Description | | ------------- | --------------------------------------------------------------- | -------------------------------------------- | | command | 'entry' | 'exit' | | | configDir | string | URL | | | ipChangeCB | function | | | validatePorts | boolean | if it waits for the proxy port to be open | | restart | boolean | if it should restart tuna if already running |

waitConnected ⇒ Promise<string>

Awaits tuna client being connected.

Returns: Promise<string> - the current ip

| Param | Type | Description | | ------------- | -------------------- | -------------------------------------------------------------------------------------------- | | validatePorts | boolean | if it waits for the proxy port to be open | | start | boolean | if tuna should be started if not running (throws error if false and tuna is already running) |

stopTuna ⇒ Promise<void>

Stops the tuna client.

startTunaProxy ⇒ Promise<TunaHandler>

Starts a tuna proxy (http or socks5), this mode allows starting multiple proxies and there is no interference between each process. Port is assigned randomly by OS, and one can retrieve it from the return value listenPort

Known issues:

  1. This package relies on reading the log output stream from tuna to determine if connected and to what ip. Due to the limitation of the output, there is no way to determine which serivce disconnects and connects belong to. So in the configuration you must only have 1 service defined, it will throw error otherwise
  2. Tuna does not fail or report an error if the defined service binding port is already in use, so is up to you to make sure is not.

Improvments for the future

  • Ability to start multiple (currently the process is global, so only one at the time can be started). One of the limitations is config directory, currently at best I could do a global map per config directory. However looking at more general solution options
  • Handle all errors from the tuna output
  • Better docs for startTunaProxy
  • implement similar solution for startTuna