本文翻译自:How to uninstall npm modules in node js?

As commonly known, any npm module can be installed by running a simple command: npm install <module_name> . 众所周知,可以通过运行一个简单的命令来安装任何npm模块: npm install <module_name>

I have installed a few modules that I do not use anymore and I just want to get them off. 我已经安装了一些不再使用的模块,我只想把它们取下来。 I have a few questions regarding this: 我对此有一些疑问:

  • Do we have any command or process to uninstall a module from the root (something like npm uninstall <module_name> ) or will simply removing the module files do? 我们是否有任何命令或过程从根目录卸载模块(类似于npm uninstall <module_name> ),还是只是删除模块文件呢?

  • How does it affect us if we keep the unused modules? 如果我们保留未使用的模块,它将对我们有何影响?


#1楼

参考:https://stackoom.com/question/spCW/如何在Node-JS中卸载NPM模块


#2楼

The command is simply npm uninstall <name> 该命令只是npm uninstall <name>

The nodejs documents https://npmjs.org/doc/ have all the commands that you need to know with npm. nodejs文档https://npmjs.org/doc/具有npm需要了解的所有命令。

A local install will be in the node_modules/ directory of your application. 本地安装将在应用程序的node_modules/目录中。 This won't affect the application if a module remains there with no references to it. 如果模块保留在那里而没有引用,则这不会影响应用程序。

If you're removing a global package however, any applications referencing it will crash. 但是,如果要删除全局软件包,则引用该全局软件包的所有应用程序都将崩溃。

Here are different options: 这是不同的选项:

npm uninstall <name> removes the module from node_modules , but not package.json npm uninstall <name>将从node_modules删除模块,但不会从package.json删除

npm uninstall <name> --save also removes it from dependencies in package.json npm uninstall <name> --save还将其从package.json dependencies中删除

npm uninstall <name> --save-dev also removes it from devDependencies in package.json npm uninstall <name> --save-dev还将其从package.json devDependencies中删除

npm -g uninstall <name> --save also removes it globally npm -g uninstall <name> --save也将其全局删除


#3楼

我只是默认情况下在我的主目录下安装手写笔 ,所以我只使用npm uninstall stylus将其分离,或者您可以尝试使用npm rm <package_name>退出。


#4楼

If it doesn't work with npm uninstall <module_name> try it globally by typing -g . 如果它不能与npm uninstall <module_name>一起npm uninstall <module_name>并通过-g全局尝试。

Maybe you just need to do it as an superUser/administrator with sudo npm uninstall <module_name> . 也许您只需要以sudo npm uninstall <module_name> install sudo npm uninstall <module_name>的超级用户/管理员身份进行操作即可。


#5楼

Well to give a complete answer to this question, there are two methods : (for example we call the installed module as module1) 为了完全回答这个问题,有两种方法 :(例如,我们将已安装的模块称为module1)。

  1. To remove module1 without changing package.json: 要在不更改package.json的情况下删除module1:

    npm uninstall module1

  2. To remove module1 with changing package.json, and removing it from the dependencies in package.json: 通过更改package.json来删除module1,并将其从package.json中的依赖项中删除,请执行以下操作:

    npm uninstall --save module1

Note: to simplify the above mentioned commands, you can use -S instead of --save , and can use remove , rm , r , un , unlink instead of uninstall 注意:为简化上述命令,可以使用-S代替--save ,并且可以使用removermrununlink而不是uninstall


#6楼

I found this out the hard way, even if it is seemingly obvious. 即使看起来很明显,我也很难做到这一点。

I initially tried to loop through the node_modules directory running npm uninstall module-name with a simple for loop in a script. 我最初尝试在脚本中使用简单的for循环遍历运行npm uninstall module-name的node_modules目录。 I found out it will not work if you call the full path, eg 我发现如果您调用完整路径,它将无法正常工作,例如

npm uninstall module-name

was working, but 在工作,但是

npm uninstall /full/path/to/node_modules/module-name

was not working. 没有工作。

如何在Node JS中卸载NPM模块?相关推荐

  1. 如何在node.js中发出HTTP POST请求?

    如何在node.js中使用数据发出出站HTTP POST请求? #1楼 如果您使用请求库,这会变得更容易. var request = require('request');request.post( ...

  2. 如何在Node.js中打印堆栈跟踪?

    本文翻译自:How to print a stack trace in Node.js? 有谁知道如何在Node.js中打印堆栈跟踪? #1楼 参考:https://stackoom.com/ques ...

  3. Node.js中的npm与包

    npm与包 一.包 1.包是什么? 2.包是干啥的? 3.包的下载 二.npm初体验 1.在项目中安装包的命令 2.eg:对时间格式化 3.安装指定版本的包 三.包管理配置文件 1.如何记录项目中安装 ...

  4. 如何在Node.js中获取本机本地IP地址

    最近在做Cloud related的项目时,遇到一个问题,就是如何在Node.js中获取本机的IP地址.Node.js提供的API中,只能获取本机的hostname. os = require('os ...

  5. 如何在Node.js中处理POST数据?

    如何提取Node.js中 HTTP POST方法发送的表单数据( form[method="post"] )和文件上传? 我已经阅读了文档,谷歌搜索并没有发现任何东西. funct ...

  6. 如何在Node.js中退出

    用于退出的命令是什么? (即终止Node.js进程) #1楼 从命令行, .exit就是你想要的: $ node > .exit $ 它在REPL文档中有记录 . REPL(Read-Eval- ...

  7. Node.js中的child_process模块详解

    本文主要给大家介绍了关于Node.js中child_process模块的相关内容,在介绍child_process模块之前,先来看一个例子. const http = require('http'); ...

  8. php能反序列化js的吗,javascript – 如何在node.js中反序列化PHP会话?

    我将 PHP $_SESSION数据存储在数据库中. 然后从Node.js服务器,我想获取该数据并反序列化它. con.query('SELECT user_id, data ' + 'FROM se ...

  9. node.js中的uniqid模块

    概括:它将始终根据当前时间,进程和计算机名称创建唯一的ID 使用:npm install uniqid var uniqid = require('uniqid');console.log(uniqi ...

最新文章

  1. (二)OpenStack---M版---双节点搭建---数据库安装和配置
  2. javascript对XMLHttpRequest异步请求的面向对象封装
  3. Java语言学习思维导图
  4. ASP.NET之纠错
  5. LINUX 下tcp 和 udp 套接字收发缓冲区的大小决定规则 .
  6. linux进程的管理,显示及杀死
  7. 计算机应用基础word试题,计算机应用基础Word试题.doc
  8. 【springboot 踩坑记录】拦截器中无法注入bean
  9. 每个Java程序员必须知道的5个JVM命令行标志
  10. linux如何切换到root用户
  11. html中字体 楷体_HTML字体集锦-
  12. 怎样配置VSS2005中文版服务器和客户端
  13. NET CORE读取Excel.xlsx单元格内的图片,并关联当前业务ID推送图片到指定服务器...
  14. linux下设置共享目录
  15. python爬取网易云某一歌手的音乐评论
  16. 江苏省南通中学2021高考成绩查询,南通中学排名前十名,2021年南通中学排名一览表...
  17. 小程序开发--- 1. 获取数组中某个字段的值或获取列表索引
  18. 蓝海创意云丨刺杀小说家:中国第一部大规模用虚拟拍摄的真人电影
  19. 2020web前端学习路线(附全套前端视频教程+教学大纲)
  20. 拷贝信息到usim卡

热门文章

  1. Android游戏开发之OpenGL之视图-投影矩阵 杂谈
  2. 如果看懂git -help
  3. 电脑卡,eclipse Android stadio 卡,什么都卡解决方法
  4. 提供推荐——协作型过滤
  5. php json设置编码,php实现json编码的方法,phpjson编码
  6. java 打破双亲委派,为什么说java spi破坏双亲委派模型?
  7. php邮件发送失败,php服务器发送邮件失败问题解析
  8. python伪造邮件发件地址_python写一个邮箱伪造脚本
  9. Spark Worker启动源码
  10. 【iOS数据持久化】Plist使用