New to Rust? Grab our free Rust for Beginners eBook Get it free →
npm remove package: How to uninstall npm packages and dependencies

To npm remove package, you run npm uninstall <package_name> from your project directory. That single command deletes the package from node_modules, removes its entry from package.json and updates package-lock.json in one shot. There’s more to it than the basics though: dev dependencies, global packages, scoped packages and batch removals all have slightly different flags. This guide covers every variant with working examples so you know exactly which command to reach for.
How to npm remove package locally (npm uninstall)
Local packages are the npm modules that are installed in a directory when you run npm install <package_name>, and are put in the node_modules folder under this directory. The name of such packages is also referenced as keys in different dependencies sections in the package.json file of the repository.
To uninstall a local package we can use the uninstall command from npm. Doing so will remove everything npm installed on its behalf, the package from node_modules, and its reference in any dependencies, devDependencies, optionalDependencies, and peerDependencies objects in package.json.
Syntax:
npm uninstall <package_name>
If your package has a scope you may also add the scope of the package before package_name.
npm uninstall <@scope/package_name>
Example:
To explain the npm uninstall command, I have taken an existing Node.js project where you can see nodemon is installed as a dev dependency. For reference, a dev dependency is a package that is only used during development.

Run the following commands in your terminal to uninstall and remove nodemon from the project:
npm uninstall nodemon
Output:

You can find nodemon has been completely removed from the local project. Secondly, the devDependencies section has also been removed because there are no devDependencies in the project.
Using npm uninstall to remove local packages from node_modules without updating package.json
Additionally, we can also remove everything that belongs to the local package but still keep its reference in the project’s package.json file using a –no-
Syntax:
npm uninstall --no-save <package_name>
Example:
In this example, you can see we have express installed in our Node.js project and our node_modules folder has an express folder along with other dependencies of the express package.

Now let’s try uninstalling the package with the –no-save flag
npm uninstall --no-save express
Output:

We can see that everything that was installed with express including express has been removed from our node_modules however, a reference to express has not been lost in our package.json.
How to npm remove package globally
Unlike local packages which can be found in the node_modules of our project, global packages are installed at some place in our system depending on our Node installation and operating system irrespective of where we run npm install-g <package_name>.
To uninstall a global package from the system we need to use the -g flag with the uninstall command.
Syntax:
npm uninstall -g <package_name>
Example:
Open any terminal/PowerShell and run the below command.
npm list -g
This will give you the list of globally installed npm modules. In my system, I have the following packages installed.
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
To follow along you may install any package such as React globally using the following command:
npm install -g react
Now, we will uninstall the globally installed react package with the following command:
npm uninstall -g react
Output:
Once the uninstallation is over, again run npm list -g to see the new list of globally installed packages and as expected we won’t find our React package in the list.

Remove a dev dependency
When you want to npm remove package entries that only live in devDependencies, the plain npm uninstall <package> command still works. npm figures out which section the package is in and removes it automatically. But if you want to be explicit, you can pass the -D or --save-dev flag. This makes the intent clear when reading the command in a CI script or a Makefile.
Syntax:
npm uninstall -D <package_name>
# or equivalently
npm uninstall --save-dev <package_name>
Example:
Say you have jest installed as a dev dependency and want to switch to vitest. Remove jest first:
npm uninstall -D jest
You’ll see the package vanish from devDependencies in package.json and from node_modules. The --save-dev flag is useful if your .npmrc has save=false set, because in that case bare npm uninstall won’t touch package.json at all. Passing the flag explicitly forces the update regardless.
The --save or -S flag targets dependencies in the same way. You rarely need it since npm 5 (released 2017) made saving the default behavior, but it’s available for environments running older configs:
npm uninstall --save express
If you’re curious about what -S actually does under the hood, we have a full breakdown in our guide to the –save option for npm install.
Remove multiple npm packages at once
You don’t need to run a separate command for each package. Pass multiple package names separated by spaces and npm will process them in one pass:
npm uninstall package1 package2 package3
Example:
Say you’re removing a set of testing utilities you no longer use:
npm uninstall jest ts-jest @types/jest
Output:
removed 28 packages, and audited 312 packages in 4s
All three packages and their sub-dependencies get removed from node_modules in one shot. Their entries also disappear from package.json and package-lock.json at the same time. This saves time compared to running three separate commands and is useful when cleaning up after swapping one library for another. Moving from Mocha and Chai to Vitest, for example, means removing several packages at once.
For global packages, the same space-separated pattern works with the -g flag:
npm uninstall -g create-react-app serve
Remove a specific version of a package
Sometimes you don’t want to remove a package entirely, just a particular version. You can target a version by appending @version to the package name:
npm uninstall <package_name>@<version>
Example:
To remove Express 4.18.x:
npm uninstall [email protected]
Output:
removed 65 packages, and audited 1 package in 1s
This is most useful in monorepos or workspaces where multiple versions of the same library can coexist, and you need to clean up a pinned older version without touching the one other packages depend on. For regular single-version projects, plain npm uninstall express is sufficient.
If you need to install a replacement at a precise version right after, see our article on installing a specific version of an npm package.
Confirm package uninstallation
After running npm uninstall, it’s worth verifying the package is actually gone. There are two places to check.
Check node_modules directly:
On macOS and Linux:
ls node_modules | grep <package_name>
On Windows:
dir node_modules
If the package folder is still there, the uninstall did not complete cleanly. Re-run the command or check that you’re in the right project directory.
Use npm ls:
The npm ls command lists the full dependency tree of your project. Running it after an uninstall shows whether the package still appears anywhere:
npm ls
For global packages:
npm list -g
If the package no longer shows up, you’re clean. We cover listing installed packages in more depth in our article on how to get a list of installed npm packages.
Clean up unused dependencies with npm prune
After working on a project for a while, your node_modules folder can drift out of sync with package.json. This happens when you manually edit package.json to remove a dependency entry but forget to delete the actual folder in node_modules. It also happens when you switch branches frequently and skip running npm install between them.
The npm prune command scans node_modules and removes anything not listed in package.json:
npm prune
Output:
removed 7 packages in 1.2s
This does not touch package.json at all. It only cleans up what’s physically on disk. Think of it as a consistency check: if your node_modules and your package.json disagree, npm prune brings node_modules back in line.
Running npm prune is useful after manually removing a dependency from package.json instead of using npm uninstall. The npm uninstall command handles both in one step, so if you’re starting fresh it’s always the right tool. But on older projects where manual edits have accumulated, a npm prune pass can trim hundreds of megabytes of stale packages you didn’t know were sitting there.
npm uninstall vs manually editing package.json
A common question is whether it’s safe to delete a package from package.json directly instead of using the command. The answer depends on what you want to happen.
If you delete a package entry from package.json and run npm install, npm will remove it from the lockfile and node_modules on the next install. So it works, eventually. The problem is that the package folder stays in node_modules until that next npm install runs. Anyone pulling the repo and running npm install from the lockfile will get a consistent state, but your local environment has a stale folder sitting there in the meantime.
npm uninstall does everything atomically. It deletes from node_modules, updates package.json and package-lock.json all at once. There’s no window where the state is inconsistent. In a CI/CD pipeline or a team environment where package-lock.json is committed to source control, you want this atomic behavior.
The only scenario where manual editing makes sense is batch cleanup: removing ten or fifteen packages from package.json at once and then running npm install --package-lock-only to resync the lockfile without touching node_modules. For anything less than that, npm uninstall is the right call.
Uninstall all globally installed npm packages
There’s no built-in command to wipe all global packages at once. The closest thing is combining npm list -g with npm uninstall -g via a shell pipe.
On macOS and Linux (bash or zsh):
npm list -g --depth=0 --parseable | grep node_modules | xargs -I{} basename {} | xargs npm uninstall -g
This lists all global packages, strips the path down to just the package name and passes each one to npm uninstall -g.
On Windows (PowerShell):
npm list -g --depth=0 --parseable --silent | Where-Object {$_ -match 'node_modules'} | ForEach-Object {npm uninstall -g (Split-Path $_ -Leaf)}
Before running either command, save your global package list so you can reinstall what you actually need later:
npm list -g --depth=0 > global-packages-backup.txt
A safer option is npm-check, an interactive tool that shows outdated and unused packages with a checklist UI:
npm install -g npm-check
npm-check -g -u
This lets you pick exactly which globals to remove rather than nuking everything. It’s the right approach if you have a mix of tools you actively use (like nodemon or ts-node) alongside old packages you forgot about. After a cleanup run, clear the cache as well:
npm cache clean --force
You can read more about where npm installs packages globally on your system if you want to understand the path structure before running these commands.
Key Takeaways
- No built-in command removes all globals at once. Combine
npm list -gwithnpm uninstall -gvia a shell pipe npm uninstall <package>removes the package fromnode_modulesand frompackage.jsonin one step- Pass
-gto remove a globally installed package from your system - Use
-Dor--save-devto explicitly target and remove a dev dependency entry - Pass multiple package names separated by spaces to remove them in a single command
--no-saveremoves fromnode_modulesbut leavespackage.jsonandpackage-lock.jsonuntouchednpm uninstall <package>@<version>targets a specific version, which is most useful in monoreposnpm prunecleans up packages left innode_modulesthat aren’t listed inpackage.json
Frequently Asked Questions (FAQs)
What is the command to remove an npm package from a project?
Run npm uninstall <package_name> from your project root. This removes the package from node_modules, package.json and package-lock.json in one step.
Does npm uninstall also remove from package-lock.json?
Yes. npm uninstall updates package.json, package-lock.json and npm-shrinkwrap.json all at once. Pass --no-save if you want to remove from node_modules only and leave those files untouched.
How do I remove a dev dependency with npm?
Run npm uninstall -D <package_name> or npm uninstall --save-dev <package_name>. This removes the package from devDependencies in package.json and deletes it from node_modules.
Can I remove multiple npm packages in one command?
Yes. List the package names separated by spaces: npm uninstall package1 package2 package3. npm removes all of them and updates package.json and package-lock.json in a single pass.
What is the difference between npm uninstall and npm prune?
npm uninstall removes a named package from node_modules and from package.json. npm prune removes any package present in node_modules that isn’t listed in package.json but does not touch package.json itself. Use npm prune after manual edits to package.json.
How do I remove a globally installed npm package?
Run npm uninstall -g <package_name>. This removes the package from your system’s global node_modules folder regardless of which project directory you are currently in.
References
- https://docs.npmjs.com/uninstalling-packages-and-dependencies
- https://stackoverflow.com/questions/13066532/how-can-i-uninstall-npm-modules-in-node-js




