0

Starting using Node.js and npm yesterday, so maybe this is a stupid question. Anyway, I'm going to use the counterparts in apt-system to describe my question. On apt-based Linux, installation is like

$ su --command='apt-get install foo'

It installs package foo and all dependencies of foo as well. Let's assume the dependencies are bar and baz, that is, the dependency hierarchy of foo is

foo
|- bar
`- baz

Now let's remove package foo with this command

$ su --command='apt-get remove --purge foo'

Both packages bar and baz will still exist in the system, even though they are no longer needed, because foo is gone. We can use next command to remove them, both bar and baz, the dependencies of foo.

$ su --command='apt-get autoremove --purge'

My question is: In npm world, is there a similar command that can remove packages like apt-get autoremove --purge does to packages of Linux distro?

Assume qux, quux and corge are Node.js packages, and the dependency hierarchy is

qux
|- quux
`- corge

As far as I know, if removing package qux with npm uninstall qux, then packages quux and corge will still exist. How to remove them, those packages that were automatically installed by npm install qux? Thanks.

Cody
  • 609
  • 4
  • 21
  • Does this answer your question? [npm command to uninstall or prune unused packages in Node.js](https://stackoverflow.com/questions/21417014/npm-command-to-uninstall-or-prune-unused-packages-in-node-js) – smac89 Dec 25 '19 at 07:08
  • @smac89 No, it doesn't, but I just figured out where I went wrong. It seems that there should be a file named package.json in the current working directory before installing anything with `npm`. Otherwise, the dependencies will be left intact after uninstalling the package that was installed by `npm`. Thanks for replying. Have a nice day. :) – Cody Dec 25 '19 at 08:13
  • 1
    You don't need a `package.json` if you used `npm -g install ...` i.e. install package globally – smac89 Dec 25 '19 at 08:14

0 Answers0