How to uninstall all npm packages with one command

The npm uninstall command is used to remove installed npm packages on your computer.

But unlike the npm install command, the uninstall command requires you to name the package you want to remove.

Running the command without stating the package name will produce an error:

$ npm uninstall
npm ERR! Must provide a package name to remove

Fortunately, you can remove multiple packages installed on your computer together:

$ npm uninstall express cross-env lodash

But this command is still inefficient because you need to name the packages one by one.

The best way to uninstall all npm packages is by removing the node_modules/ folder and the package-lock.json file.

Run the following commands using Bash or ZSH:

rm -rf node_modules
rm package-lock.json

Or if you use the Windows Command Prompt:

del package-lock.json
rmdir /s node_modules

And all npm packages installed locally will be uninstalled.

Uninstall all global npm packages

If you want to uninstall all global packages, then you need to name the packages one by one in the npm uninstall -g command.

Run the npm list -g --depth=0 command to list the packages installed globally on your computer.

Use that list to uninstall the packages:

$ npm uninstall -g <package name> <package name> <package name>

That should uninstall all global packages for you. But please note that you shouldn’t uninstall the npm global package because you will break the npm commands.

Now you’ve learned how to uninstall all npm packages, both locally and globally. Good work! 👍

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.