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

npmrc-switcher

v0.1.0

Published

npmrc 多环境切换工具:CLI + 本地 Web,支持环境保存、一键切换、自动备份与分发

Readme

npmrc-switcher

npmrc 多环境切换工具:命令行 + 本地网页双入口,用来在多套 npm registry / 鉴权配置之间快速切换。

适用场景:公司内网 Artifactory 源、npmmirror 公共源、不同账号 token 等配置来回切换,不用再手动改 ~/.npmrc。

  • 零运行时依赖,只用 Node 内置模块(Node >= 18)
  • 切换前自动备份,写坏了一秒恢复
  • 网页只监听 127.0.0.1,敏感值默认脱敏展示

安装

# 方式一:本地直接运行(无需安装)
node bin/npmrc.js <命令>

# 方式二:链接为全局命令 npmrc
npm link          # 或 npm install -g .
npmrc --version

快速开始

# 1. 把公司源的 npmrc 存成环境
npmrc add company D:\configs\company.npmrc

# 2. 列出所有环境(* 为当前生效)
npmrc ls

# 3. 切换(会备份当前 ~/.npmrc 后覆盖写入)
npmrc use company

# 4. 把当前 npmrc 复制到某个项目目录,供该项目使用
cd D:\some-project
npmrc copy                 # 生成 ./.npmrc

# 5. 打开网页版,功能与命令行一致
npmrc serve                # 默认 http://127.0.0.1:8848/ 并自动打开浏览器

命令一览

| 命令 | 说明 | |------|------| | npmrc ls | 列出所有环境:序号、名称、大小、修改时间、来源、生效标记 | | npmrc use <名称> | 切换环境;不带参数时交互式选择 | | npmrc add <名称> <文件> | 关联 npmrc 文件并保存为环境(文件被复制进工具数据目录) | | npmrc add <文件> | 名称缺省取文件基名(去掉 .npmrc) | | npmrc add --from-current <名称> | 把当前 npmrc 快照为一个新环境 | | npmrc add | 向导模式:名称 + 文件路径 / 直接粘贴内容 | | npmrc copy [-o 路径] [-f] | 把当前 npmrc 复制到当前目录 .npmrc;-o 指定目录或文件,-f 覆盖 | | npmrc serve [-p 端口] [--no-open] [--host] | 启动网页服务并打开浏览器;端口被占用自动顺延 | | npmrc current [--raw] | 查看默认 npmrc 路径、registry、生效环境与内容(默认脱敏) | | npmrc rm <名称> [-y] | 删除环境及其文件 | | npmrc edit <名称> | 用 $EDITOR(Windows 回退 notepad)打开环境文件 | | npmrc backups | 列出自动备份 | | npmrc help / npmrc -v | 帮助 / 版本 |

退出码:0 成功,1 业务失败,2 参数错误。

网页版

npmrc serve 后访问 http://127.0.0.1:8848/,包含命令行全部能力并额外支持:

  • 环境列表:一键切换 / 编辑 / 删除,生效中徽标
  • 新增环境三种方式:粘贴内容、键值对表单、服务器文件路径导入;另支持「从当前 npmrc 快照」
  • 当前 npmrc 查看:_auth、token、email、URI 内 user:pass@ 默认打码,可切换显示原文
  • 复制当前 npmrc 到任意目录
  • 备份列表与一键恢复

数据与路径

| 内容 | 默认位置 | 覆盖方式 | |------|----------|----------| | 数据根目录 | %USERPROFILE%\.npmrc-switcher | 环境变量 NPMRC_SWITCHER_HOME | | 环境文件 | {数据根}\envs\<名称>.npmrc | — | | 配置登记 | {数据根}\config.json | — | | 自动备份 | {数据根}\backups\<时间戳>_<名称>.npmrc(保留最近 20 份) | — | | 默认 npmrc | npm config get userconfig(通常 %USERPROFILE%\.npmrc) | 环境变量 NPMRC_TARGET |

「切换」= 把环境文件内容原子覆盖写入默认 npmrc:先备份原文件,再写临时文件后 rename,最后回读校验,任一步失败都不动原文件。

「生效环境」按内容 SHA256 比对判定,因此手工改过 ~/.npmrc 后会显示「无匹配环境」,不会误标。

安全说明

  • 网页服务仅绑定 127.0.0.1,不要把 --host 0.0.0.0 暴露到局域网。
  • npmrc 内含 token / 密码,页面默认脱敏;需要原文时手动开 --raw 或勾选「显示原文」。
  • 从文件路径导入 由服务端读文件,属于本机特权操作,仅在本机使用。

开发

npm test        # node --test,24 个用例(不触碰真实 ~/.npmrc,全部用临时目录隔离)
npm start -- ls

目录结构:

bin/npmrc.js            CLI 入口
src/cli.js              命令解析与实现
src/paths.js            路径解析(数据目录 / 默认 npmrc)
src/store.js            环境与配置持久化、备份轮转
src/npmrc.js            npmrc 解析、脱敏、摘要
src/apply.js            use / copy / 导入核心逻辑
src/server/             本地 HTTP 服务与单页 UI
test/                   node:test 单元测试