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

@apofasi/socks

v1.3.1

Published

A modern SOCKS5 server implementation with TypeScript support, forked from simple-socks

Downloads

164

Readme

@apofasi/socks

A modern SOCKS5 server implementation with TypeScript support. This package is a modernized TypeScript fork of simple-socks, providing enhanced type safety and modern JavaScript features.

Credits

This project is based on simple-socks by brozeph. We've made the following improvements:

  • Full TypeScript rewrite with complete type definitions
  • Modern JavaScript features and best practices
  • Enhanced error handling and type safety
  • Improved documentation and examples
  • Zero production dependencies

Features

  • Full SOCKS5 protocol support (RFC 1928)
  • Username/password authentication (RFC 1929)
  • TypeScript support with complete type definitions
  • Support for IPv4, IPv6, and domain name resolution
  • Customizable socket factory for connection handling
  • Connection filtering capabilities
  • Event-based architecture
  • Zero production dependencies

Installation

npm install @apofasi/socks

Basic Usage

Creating a Simple SOCKS5 Server

import { createServer } from '@apofasi/socks';

// Create a server without authentication
const server = createServer();

// Start listening
server.listen(1080, '127.0.0.1', () => {
  console.log('SOCKS5 server listening on 127.0.0.1:1080');
});

Creating a Server with Authentication

import { createServer } from '@apofasi/socks';

// Create a server with authentication
const server = createServer({
  authenticate: (username, password, socket, callback) => {
    if (username === 'user' && password === 'pass') {
      callback(); // Authentication successful
    } else {
      callback(new Error('Authentication failed'));
    }
  }
});

server.listen(1080, '127.0.0.1', () => {
  console.log('SOCKS5 server with authentication listening on 127.0.0.1:1080');
});

Custom Socket Factory

import { createServer } from '@apofasi/socks';
import { SocksClient } from 'socks';

// Create a server that chains to another SOCKS5 proxy
const server = createServer({
  socketFactory: async (destinationAddress, destinationPort) => {
    const { socket } = await SocksClient.createConnection({
      proxy: {
        host: 'next-proxy.example.com',
        port: 1080,
        type: 5,
      },
      command: 'connect',
      destination: {
        host: destinationAddress,
        port: destinationPort,
      },
    });
    return socket;
  }
});

server.listen(1080);

API Reference

createServer(options?)

Creates a new SOCKS5 server instance.

Options

  • authenticate?: (username: string, password: string, socket: Socket, callback: (err?: Error) => void) => void

    • Optional authentication handler
    • Called when a client attempts to authenticate
    • Call callback() for success, callback(error) for failure
  • socketFactory?: (address: string, port: number) => Promise<Duplex>

    • Optional custom socket factory
    • Called when establishing connections to destinations
    • Useful for chaining proxies or custom connection handling
  • connectionFilter?: (destination: { address: string, port: number }, origin: { address: string, port: number }, callback: (err?: Error) => void) => void

    • Optional connection filter
    • Called before establishing connections
    • Can be used to implement access control

Server Events

  • authenticate - Emitted on successful authentication
  • authenticateError - Emitted on authentication failure
  • connectionFilter - Emitted when connection filtering occurs
  • proxyConnect - Emitted when a proxy connection is established
  • proxyData - Emitted when data is transferred
  • proxyError - Emitted on proxy errors
  • proxyEnd - Emitted when a proxy connection ends

Testing

npm test

Contributing

This project is a fork of simple-socks and follows its core design principles while adding modern TypeScript support. Contributions are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run the tests (npm test)
  5. Commit your changes (git commit -m 'feat: add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Scripts

# Install dependencies
npm install

# Run tests
npm test

# Build the package
npm run build

# Lint code
npm run lint

# Format code
npm run format

# Publish new versions
npm run publish-patch  # For bug fixes (1.1.0 -> 1.1.1)
npm run publish-minor  # For new features (1.1.0 -> 1.2.0)
npm run publish-major  # For breaking changes (1.1.0 -> 2.0.0)

License

MIT

Acknowledgments

  • simple-socks - The original project this is forked from
  • RFC 1928 - SOCKS Protocol Version 5
  • RFC 1929 - Username/Password Authentication for SOCKS V5