Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 282 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I uninstall npm modules in Node.js?

#1
As commonly known, any npm module can be installed by running a simple command: `npm install <module_name>`.

I have installed a few modules that I do not use any more 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?

- How does it affect us if we keep the unused modules?


Reply

#2
I just install *stylus* by default under my home dir, so I just use `npm uninstall stylus` to detach it, or you can try `npm rm <package_name>` out.
Reply

#3
If it doesn't work with `npm uninstall <module_name>` try it globally by typing `-g`.

Maybe you just need to do it as an superUser/administrator with `sudo npm uninstall <module_name>`.
Reply

#4
Additionally, if you've started using `yarn`, in place of `npm`:
`yarn remove <package-name>`

Is the equivalent of:
`npm uninstall <package-name> --save`

This will
- remove the package from `package.json`, as well as
- uninstall it from your project's `node-modules` folder

Reply

#5
To uninstall a module using npm, you can use:
```
npm uninstall moduleName
```
Also, if you want to uninstall and want the change to be reflected in your package.json then you can use the --save flag, like this:
```
npm uninstall moduleName --save
OR
npm uninstall -S
```
And if you want to uninstall a module from devDependencies and want the change to be reflected in package.json then you can use -D flag, like this:
```
npm uninstall moduleName -D
```
Reply

#6
You can also run the following as shorthand:

`npm un packageName` or `npm rm packageName`

Note: Add `-g` at end of command to uninstall global packages.
Reply

#7
The command is simply `npm uninstall <name>`

The Node.js documents

[To see links please register here]

have all the commands that you need to know with npm.

A local install will be in the `node_modules/` directory of your application. 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 does not update `package.json`

`npm uninstall <name> --save` also removes it from `dependencies`in `package.json`

`npm uninstall <name> --save-dev` also removes it from `devDependencies` in `package.json`

`npm uninstall -g <name> --save` also removes it globally
Reply

#8
Well, to give a complete answer to this question, there are [two methods][1] (for example we call the installed module as module1):

1. To remove module1 **without** changing package.json:

`npm uninstall module1`

2. To remove module1 **with** changing package.json, and removing it from the dependencies in 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**

[1]:

[To see links please register here]


Reply

#9
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. I found out it will not work if you call the full path, e.g.,

npm uninstall module-name

was working, but

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

was not working.
Reply

#10
To uninstall the Node.js module:

npm uninstall <module_name>

This will remove the module from folder *node_modules*, but not from file *package.json*. So when we do npm install again it will download the module.

So to remove the module from file *package.json*, use:

npm uninstall <module_name> --save

This also deletes the dependency from file *package.json*.

And if you want to uninstall any globally module you can use:

npm -g uninstall <module_name> --save

This will delete the dependency globally.


Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through