npm包管理命令学习笔记

7 阅读1分钟

一.npm常用命令

  1. npm --version 查看版本

image.png

  1. npm root -g 查看安装目录

image.png

3.远程拉取playwright-mcp-server到本地缓存目录 npx -y --registry=registry.npmmirror.com@executeautomation/playwright-…

image.png

4.npm config get cache 查看缓存目录

image.png

5.where node 查看node安装目录

image.png

  1. node -v 查看node版本

image.png

  1. npm install -g @executeautomation/playwright-mcp-server 全局安装@executeautomation插件

  2. npm list -g 查看@executeautomation插件的位置

image.png

注意:npm 全局安装的包默认不会放在 Node.js 的安装目录(D:\Program Files\SoftInstall\Nodejs\node_modules\npm\node_modules)下,这是 npm 的默认设计行为。

  1. npx playwright install chromium 安装 chromium浏览器

image.png

  1. npx playwright uninstall 可以移除所有已安装的浏览器

二. 设置国内镜像

要将 npm install -g @executeautomation/playwright-mcp-server改为使用国内镜像下载,主要有以下几种方法:

方法一:使用 cnpm(淘宝镜像的客户端)

这是最直接的方式,cnpm会自动使用淘宝的镜像源。

  1. 安装 cnpm(如果尚未安装):

    npm install -g cnpm --registry=https://registry.npmmirror.com
    
  2. 使用 cnpm 安装

    cnpm install -g @executeautomation/playwright-mcp-server
    

方法二:临时使用镜像源(单次命令)

npm install命令后添加 --registry参数,指定镜像地址。

npm install -g @executeautomation/playwright-mcp-server --registry=https://registry.npmmirror.com

方法三:永久切换 npm 的镜像源(推荐)

直接修改 npm 的默认 registry 配置,这样以后所有 npm install命令都会使用国内镜像。

  1. 设置淘宝镜像

    npm config set registry https://registry.npmmirror.com
    
  2. 验证是否设置成功

    npm config get registry
    

    如果返回 https://registry.npmmirror.com就表示设置成功了。

  3. 之后正常安装即可

    npm install -g @executeautomation/playwright-mcp-server
    

常用国内镜像地址

  • 淘宝镜像https://registry.npmmirror.com
  • 腾讯云镜像https://mirrors.cloud.tencent.com/npm/
  • 华为云镜像https://repo.huaweicloud.com/repository/npm/