CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

npm

$ npm 官方出品 中风险
npm / GitHub · 代码托管与研发协同 · Artistic-2.0 · macos / linux / windows

随 Node.js 内置的标准命令行工具,用于管理 package.json、package-lock.json、脚本与包仓库。在 ls、outdated、audit、view、install --dry-run 与 publish --dry-run 上均原生支持 --json,并可通过 --ignore-scripts 与 npm ci 实现确定性安装。

FCRS-1.0 综合评分
84 /100
良好 (Good)
高置信度 (实测)
零摩擦安装命令
npm install -g npm
CLI vs MCP 选型建议 仅 CLI 可用

与 node_modules 及 package-lock.json 紧密绑定的本地 Node.js 包与脚本管理 CLI。

Agent 友好度体检单

本地探针实测证据
✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
✓ 支持 Dry-Run
— 只读模式开关
✓ 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md
实测版本
11.19.1
冷启动耗时
101 ms
退出码 (help / 非法参数)
1 / 1
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --help 摘要
npm <command>

Usage:

npm install        install all the dependencies in your project
npm install <foo>  add the <foo> dependency to your project
npm test           run this project's tests
npm run <foo>      run the script named <foo>
npm <command> -h   quick help on <command>
npm -l             display usage info for all commands
npm help <term>    search for help on <term>
npm help npm       more involved overview

All commands:

    access, adduser, approve-scripts, audit, bugs, cache, ci,
    completion, config, dedupe, deny-scripts, deprecate, diff,
    dist-tag, docs, doctor, edit, exec, explain, explore,
    find-dupes, fund, get, help, help-search, init, install,
    install-ci-test, install-scripts, install-test, link, ll,
    login, logout, ls, org, outdated, owner, pack, ping, pkg,
    prefix, profile, prune, publish, query, rebuild, repo,
    restart, root, run, sbom, search, set, shrinkwrap, stage,
    star, stars, start, stop, team, test, token, trust,
    undeprecate, uninstall, unpublish, unstar, update, version,
    view, whoami

Specify configs in the ini-formatted file:
    /Users/pcyan/.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config

[email protected] /opt/homebrew/Cellar/node@24/24.22.0/lib/node_modules/npm

FCRS-1.0 六维评分拆解

Agent 友好度 19 / 25

ls、audit、outdated、view、install 与 publish 广泛支持 --json,并具备 --dry-run、--no-color、--no-fund 与 -y。

  • Native --json and --dry-run on core commands
  • Deterministic npm ci mode
安全与权限边界 19 / 25

支持 --dry-run 与 --ignore-scripts,但默认 npm install 会执行依赖包中的 preinstall/postinstall 任意脚本。

  • Lifecycle script execution risk mitigated by --ignore-scripts
安装与运行摩擦 14 / 15

随 Node.js 安装包预装在 macOS、Linux 与 Windows 全平台。

  • Bundled by default with Node.js
能力覆盖与边际价值 14 / 15

Node.js 生态最通用的包管理与脚本执行入口(npm run、npm exec)。

  • Standard registry and workspace tooling
维护与来源背书 10 / 10

由 GitHub/npm 官方团队(npm/cli)以 Artistic-2.0 协议维护。

  • Official npm/cli repository
文档与可验证性 8 / 10

docs.npmjs.com 与 npm help <cmd> 提供完整命令手册。

  • Official documentation at docs.npmjs.com/cli

安全边界、鉴权与放权指南

鉴权方式
无需鉴权 本地配置文件 环境变量密钥
凭证存储位置

从 ~/.npmrc(_authToken)或 NPM_TOKEN 环境变量读取仓库令牌;本地只读命令无需认证。

潜在副作用
只读查询 本地写入 远端写入
费用与配额提示

Artistic-2.0 开源 CLI;公共 npm 仓库拉取与开源包发布均免费。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# npm Agent Rules
- Prefer `npm ci --ignore-scripts` over `npm install` on existing repos to avoid lockfile drift and untrusted `postinstall` scripts.
- Always preview with `npm publish --dry-run` and never publish without explicit user confirmation.

Agent 高频安全命令配方

只读查询(安全推荐)

以 JSON 导出依赖树与安全审计结果
npm ls --depth=0 --json && npm audit --json

以结构化 JSON 输出顶层已安装依赖及已知漏洞公告。

不写磁盘预演包安装计划
npm install --dry-run --json

模拟依赖解析并以 JSON 返回预计新增或更新的包列表。

受控写入与预演

禁用生命周期脚本按锁文件纯净安装
npm ci --ignore-scripts --no-audit --no-fund

严格依据 package-lock.json 还原 node_modules,同时阻断 postinstall 脚本执行。

核心优势

  • + --json 与 --dry-run 贯穿依赖查询、安装预演与发布预检。
  • + 随 Node.js 预装且可用 npm ci 严格复现锁文件状态。

注意事项与踩坑点

  • ! 默认 npm install 会触发 postinstall 生命周期脚本,处理不受信任项目需显式加 --ignore-scripts。
  • ! 磁盘安装速度与幽灵依赖隔离性弱于 pnpm。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI