Is there a command to remove all global npm modules? If not, what do you suggest?

推荐答案

The following command removes all global npm modules. Note: this does not work on Windows. For a working Windows version, see Ollie Bennett's Answer.

npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm

Here is how it works:

  • npm ls -gp --depth=0 lists all global top level modules (see the cli documentation for ls)
  • awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' prints all modules that are not actually npm itself (does not end with /npm)
  • xargs npm -g rm removes all modules globally that come over the previous pipe

Node.js相关问答推荐

Twilio-获取呼叫录音不起作用的请求

如何在mongodb集合中设置数据限制?

Gmail API获取附件PDF未正确呈现.我遗漏了什么?

聚合操作不返回任何具有mongoose模式的内容

填充函数在Node.js和MongoDB中不起作用

NodeJS `request` 库无法通过 multipart-form-data 将文件发布到 dotnet 服务器

如何解决未调用 Express 错误处理程序的问题

在路由上使用中间件时,Nodejs Express 应用程序失败

级联定时器和Jest 的异步功能

Mongodb 从文档中获取聚合结果中的特定属性

在 NodeJS/ESP32 中通过 WebSocket 发送二进制数据 - 如何识别二进制和文本消息

Mongoose,如何一次更新多个?

tsc:当我上传 React+next js 和 node 项目时,在 heroku 找不到

try 运行迁移时的 Typeorm:缺少必需的参数:dataSource

如何undo撤消 Object.defineProperty 调用?

ChildProcess 关闭、退出事件之间的区别

Puppeteer 记录在 page.evaluate

Forever + Nodemon 一起运行

yarn 和 npm 的主要区别是什么?

我无法全局安装 nodemon,nodemon无法识别