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 🙏

© 2026 – Pkg Stats / Ryan Hefner

clash-node

v0.0.1

Published

A Node.js CLI proxy tool similar to Clash

Readme

clash-node

一个基于 Node.js 的命令行代理工具,类似于 Clash,支持多种代理协议和智能分流规则。

功能特性

  • 🚀 多协议支持:HTTP/HTTPS、SOCKS5
  • 🔄 智能分流:基于域名、IP、GeoIP 的规则引擎
  • 📡 订阅管理:支持 Clash 的订阅格式
  • 🖥️ 系统代理:自动配置 MacOS/Windows 系统代理
  • 🔍 节点测试:延迟测试和健康检查
  • 🛡️ 规则自定义:支持自定义分流规则

系统要求

  • Node.js >= 16.0.0
  • macOS / Windows

使用

安装依赖

# npm
npm i clash-node -g
# yarn
yarn global add clash-node
# pnpm
pnpm add clash-node -g

启动代理服务

# 使用默认配置启动(默认端口 7890)
cn start

# 指定端口启动
cn start -p 7890 -s 7891

2. 管理订阅

# 添加订阅
cn list -a https://example.com/clash-config

# 列出所有订阅
cn list

# 更新订阅
cn update

# 删除订阅
cn subscription -d subscription-name

3. 管理节点

# 列出所有节点
cn node -l

# 选择节点
cn node -s "Node Name"

# 测试节点延迟
cn node -t

# 自动选择最快节点
cn node -a

4. 系统代理设置

# 查看代理状态
cn proxy --status

# 启用系统代理
cn proxy --enable

# 禁用系统代理
cn proxy --disable

5. 查看服务状态

cn status

高级用法

自定义配置文件

# 使用自定义配置文件
cn start -c /path/to/config.yaml

配置文件

默认配置文件位于 ./config/config.yaml,支持以下配置:

# 代理端口
port: 7890
socks-port: 7891

# 允许局域网连接
allow-lan: false

# 代理模式:rule | global | direct
mode: rule

# 日志级别
log-level: info

# 外部控制器
external-controller: 127.0.0.1:9090

# 代理节点
proxies:
  - name: "Example"
    type: ss
    server: example.com
    port: 8388
    cipher: aes-256-gcm
    password: password

# 代理组
proxy-groups:
  - name: PROXY
    type: select
    proxies:
      - DIRECT
      - AUTO
  - name: AUTO
    type: url-test
    proxies: []
    url: "http://www.gstatic.com/generate_204"
    interval: 300

# 分流规则
rules:
  - DOMAIN-SUFFIX,local,DIRECT
  - IP-CIDR,127.0.0.0/8,DIRECT
  - IP-CIDR,172.16.0.0/12,DIRECT
  - IP-CIDR,192.168.0.0/16,DIRECT
  - IP-CIDR,10.0.0.0/8,DIRECT
  - GEOIP,CN,DIRECT
  - MATCH,PROXY

API 接口

启动服务后,可以通过 RESTful API 进行管理:

# 获取状态
curl http://127.0.0.1:9090/status

# 获取节点列表
curl http://127.0.0.1:9090/nodes

# 选择节点
curl -X POST http://127.0.0.1:9090/nodes/NodeName/select

# 测试节点
curl -X POST http://127.0.0.1:9090/nodes/NodeName/test

# 启用系统代理
curl -X POST http://127.0.0.1:9090/system-proxy/enable

# 禁用系统代理
curl -X POST http://127.0.0.1:9090/system-proxy/disable

WebSocket 实时通信

连接到 ws://127.0.0.1:9090/ws 可以接收实时状态更新:

const ws = new WebSocket("ws://127.0.0.1:9090/ws");

ws.on("message", (data) => {
  const message = JSON.parse(data);
  console.log("Received:", message);
});

// 发送消息
ws.send(
  JSON.stringify({
    type: "getStatus",
  })
);

支持的代理协议

HTTP/HTTPS

- name: "http-example"
  type: http
  server: example.com
  port: 8080
  username: user
  password: pass

SOCKS5

- name: "socks5-example"
  type: socks5
  server: example.com
  port: 1080
  username: user
  password: pass

规则语法

支持以下规则类型:

  • DOMAIN-SUFFIX,example.com,PROXY - 域名后缀匹配
  • DOMAIN-KEYWORD,ads,REJECT - 域名关键字匹配
  • IP-CIDR,192.168.0.0/16,DIRECT - IP 段匹配
  • GEOIP,CN,DIRECT - 地理位置匹配
  • MATCH,PROXY - 最终匹配规则

平台支持

macOS

  • 自动配置网络服务代理设置
  • 支持 HTTP/HTTPS/SOCKS5 代理设置

Windows

  • 通过注册表配置系统代理
  • 支持 IE 代理设置

Linux

  • 支持 GNOME 桌面环境代理设置
  • 提供环境变量配置指导

常见问题

1. 权限问题

在 macOS 上配置系统代理需要管理员权限:

sudo clash-node proxy --enable

2. 防火墙设置

确保防火墙允许代理端口通信:

# macOS
sudo pfctl -f /etc/pf.conf

# Windows
netsh advfirewall firewall add rule name="Clash Proxy" dir=in action=allow protocol=TCP localport=7890

3. DNS 解析问题

如果遇到 DNS 解析问题,可以手动配置 DNS:

dns:
  enable: true
  nameserver:
    - 8.8.8.8
    - 1.1.1.1

开发

项目结构

clash-node/
├── bin/
│   └── cli.js              # 命令行入口
├── src/
│   ├── core/
│   │   ├── ProxyManager.js   # 代理管理器
│   │   ├── SystemProxy.js    # 系统代理设置
│   │   ├── SubscriptionManager.js # 订阅管理
│   │   ├── ConfigManager.js  # 配置管理
│   │   ├── RuleEngine.js     # 规则引擎
│   │   └── NodeManager.js    # 节点管理
│   └── index.js            # 主服务
├── config/
│   ├── config.yaml         # 配置文件
│   └── subscriptions.json  # 订阅配置
└── package.json

本地开发

# 开发模式运行
npm run dev

# 运行测试
npm test

# 构建可执行文件
npm run build

贡献

欢迎提交 Issue 和 Pull Request!

许可证

MIT License

免责声明

本工具仅供学习和研究使用,请遵守当地法律法规。