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

@raphaellcs/port-checker

v1.0.0

Published

端口占用检查工具 - 快速查看端口占用情况

Readme

@claw-dev/port-checker

端口占用检查工具 - 快速查看端口占用情况

🚀 功能

  • 检查端口:查看单个端口是否被占用
  • 批量检查:检查多个端口
  • 列出占用:列出所有占用的端口
  • 终止进程:杀掉占用端口的进程
  • 详细信息:显示进程名称、PID、用户等

📦 安装

npx @claw-dev/port-checker

📖 快速开始

1. 检查单个端口

port-checker check 3000

输出:

📋 端口占用情况

✓ 端口 3000 可用

如果被占用:

📋 端口占用情况

✗ 端口 3000 被占用
  进程: node
  PID: 12345
  命令: node /path/to/app.js
  用户: yourname

2. 检查多个端口

port-checker check-all 3000 8000 8080

检查多个端口是否被占用。

3. 列出所有占用的端口

port-checker list

输出所有被占用的端口和对应进程。

4. 杀掉占用端口的进程

port-checker kill 3000

终止占用端口 3000 的进程。

📋 命令

check

检查单个端口是否被占用。

port-checker check <port>

参数:

  • <port> - 端口号

退出码:

  • 0 - 端口可用
  • 1 - 端口被占用

check-all

检查多个端口。

port-checker check-all <port1> <port2> ...

参数:

  • <port1> <port2> ... - 多个端口号

list

列出所有占用的端口。

port-checker list

选项:

  • -p, --port <number> - 只显示指定端口

kill

杀掉占用指定端口的进程。

port-checker kill <port>

参数:

  • <port> - 端口号

警告: 此命令会终止进程,请谨慎使用。

🎯 使用场景

1. 启动服务前检查

# 检查端口是否可用
port-checker check 3000

# 如果可用,启动服务
if [ $? -eq 0 ]; then
    npm start
fi

2. 快速查看占用

# 查看端口 3000 被谁占用
port-checker list -p 3000

# 查看所有占用
port-checker list

3. 释放端口

# 终止占用端口的进程
port-checker kill 3000

4. 批量检查常用端口

# 检查常用的开发端口
port-checker check-all 3000 8000 8080 5432 27017

5. 脚本中使用

#!/bin/bash

# 启动服务前检查端口
PORT=3000

if port-checker check $PORT; then
    echo "端口 $PORT 可用,启动服务..."
    npm start
else
    echo "端口 $PORT 被占用"
    exit 1
fi

💡 提示

1. 常用端口

| 端口 | 用途 | |------|------| | 3000 | 开发服务器(Node.js/Express)| | 8080 | 备用开发服务器 | | 5432 | PostgreSQL | | 27017 | MongoDB | | 6379 | Redis | | 3306 | MySQL |

2. 安全提示

使用 kill 命令前,请确认:

  • 你知道这个进程是什么
  • 终止它不会影响其他服务
  • 你有权限终止这个进程

3. 跨平台

这个工具支持:

  • Linux
  • macOS
  • Windows(部分功能)

🔧 故障排查

1. 权限问题

查看其他用户的进程可能需要 sudo:

sudo port-checker list

2. lsof 未安装

Linux/macOS 需要 lsof 命令:

# macOS
brew install lsof

# Ubuntu/Debian
sudo apt-get install lsof

# CentOS/RHEL
sudo yum install lsof

3. 检查失败

如果检查失败,确保:

  • 端口号在有效范围内(1-65535)
  • 你有权限访问端口信息
  • lsofnetstat 可用

🚧 待实现

  • [ ] 按进程名过滤
  • [ ] 按用户过滤
  • [ ] 显示监听地址
  • [ ] 显示连接数
  • [ ] 历史记录

🤝 贡献

欢迎提交 Issue 和 PR!

📄 许可证

MIT © 梦心


Made with 🌙 by 梦心