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

safe-port

v0.1.1

Published

Pick a safe available port for Docker and local development.

Readme

safe-port

为 Docker 和本地开发挑选一个安全可用端口。

English · GitHub Pages

为什么需要

部署 Docker 服务或启动本地服务时,经常需要选择一个宿主机端口。端口不能太低,不能和常见服务冲突,也不能和当前已监听端口冲突。safe-port 提供一个无需安装的 CLI,适合脚本和一次性命令使用。

使用方式

npx safe-port

配合 Docker 使用:

PORT=$(npx safe-port)
docker run -p "$PORT:80" nginx

返回多个端口:

npx safe-port --count 3 --format json

参数

| 参数 | 说明 | 默认值 | | --- | --- | --- | | --min <number> | 最小端口 | 20000 | | --max <number> | 最大端口 | 49151 | | --exclude <ports> | 逗号分隔的排除端口 | 无 | | --count <number> | 返回端口数量 | 1 | | --host <host> | 检测主机 | 127.0.0.1 | | --format <format> | plainjsonenv | plain | | --no-avoid-common | 允许常见服务端口 | 默认不允许 | | --strict | 保留给脚本可读性;范围耗尽时本来就会失败 | 默认行为 | | -h, --help | 显示帮助 | 无 |

输出格式

普通输出:

npx safe-port
# 23456

环境变量输出:

npx safe-port --format env
# PORT=23456

JSON 输出:

npx safe-port --count 2 --format json
# {"ports":[23456,23457]}

退出码

| 退出码 | 含义 | | --- | --- | | 0 | 找到可用端口 | | 1 | 参数非法或非预期错误 | | 2 | 请求范围内没有可用端口 |

注意

safe-port 会通过临时绑定 TCP server 检测候选端口,然后立即关闭。这个方式适合脚本使用,但任何端口选择工具都无法完全保证检测完成后端口不会被其他进程抢占。

开发

npm install
npm run lint
npm test
npm run build

发布

npm 发布通过 GitHub Actions 的 Publish to npm workflow 手动执行。执行前需要在仓库 secrets 中添加 NPM_TOKEN

也可以使用本地 release 脚本:

npm run release:patch
npm run release:minor
npm run release:major

License

MIT