Developer guide · Windows and Mac
How to find and delete old node_modules folders
By Aqib Javed · Updated Nov 2, 2026
On a Mac or Linux, list every node_modules folder under your projects with find ~/projects -name node_modules -type d -prune, and add -exec rm -rf {} + to delete them. On Windows, use Get-ChildItem -Recurse -Directory -Filter node_modules in PowerShell, or run npx npkill to pick folders from a list. It's safe: npm install or npm ci rebuilds the folder from package.json and the lockfile. Stackyard, a free app, clears it in projects you haven't touched.
Is it safe to delete node_modules?
- npm install, or npm ci, which installs exactly what package-lock.json lists and needs that file to exist.
- yarn install or pnpm install in projects that use those.
- Keep the lockfile (package-lock.json, yarn.lock or pnpm-lock.yaml). Without it, a reinstall can pick newer versions than the ones you had.
- Packages with native parts run their install scripts again, so the first install after deleting takes longer.
- Global packages (npm install -g) live elsewhere and aren't affected.
Yes. node_modules only holds packages your package manager downloaded. Your code, package.json and the lockfile stay, and one command brings the folder back.
How to find every node_modules folder and its size on Mac or Linux
Run these from the folder that holds your projects. -prune stops find from going inside each node_modules, so you get one line per project instead of thousands of nested ones. The second command adds each folder's size and sorts the biggest to the bottom.
cd ~/projects
find . -name node_modules -type d -prune
find . -name node_modules -type d -prune -exec du -sh {} + | sort -hHow to delete them on Mac or Linux
Check the list first. rm -rf deletes for good, without going through the Trash. To keep the projects you're working on, run the first command in a folder that only holds old ones, or delete folders one at a time from the list.
# every node_modules under the current folder
find . -name node_modules -type d -prune -exec rm -rf {} +
# just one project, run inside it
rm -rf node_modulesHow to find and delete node_modules on Windows
Run this in PowerShell from your projects folder. It lists each node_modules with its size in GB, skips the ones nested inside other node_modules, and puts the biggest last. The last line deletes one project's folder. Deleting a large node_modules in File Explorer is slow and can fail on long paths, so the command line is the better route; npx rimraf node_modules and rd /s /q node_modules in Command Prompt work too.
cd $HOME\projects
Get-ChildItem -Recurse -Directory -Filter node_modules -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -notmatch 'node_modules.+node_modules' } |
ForEach-Object { [pscustomobject]@{ GB = [math]::Round((Get-ChildItem $_.FullName -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum / 1GB, 2); Path = $_.FullName } } |
Sort-Object GB
Remove-Item -Recurse -Force .\my-app\node_modulesPick them from a list with npkill
npkill is a free command-line tool for Mac, Windows and Linux. Run it in your projects folder and it lists every node_modules with its size; move with the arrow keys and press Space to delete the selected one. -d starts the search in another folder, and --dry-run shows what would happen without deleting anything.
npx npkill
npx npkill -d ~/projects --dry-runClearing node_modules with Stackyard
Stackyard is a free, open-source app for Windows and Mac. It scans the project folders you point it at and lists the folders in each project that come back on their own: node_modules, framework caches such as .next and .turbo, Flutter and Android build folders and iOS Pods. Projects idle for three months or more are grouped so you can clear them in one go, it warns you when a project was worked on recently, and everything goes to the Trash or Recycle Bin, so a mistake is one restore away. It never touches your code.
Questions
Can I delete node_modules and reinstall?
- Yes. Delete the folder, then run npm install, or npm ci if the project has a package-lock.json. Keep the lockfile so you get the same versions back.
Should I delete package-lock.json too?
- Usually not. The lockfile pins exact versions, and deleting it makes npm resolve everything again, which can pull in newer versions. Delete it only when you mean to refresh the whole dependency tree.
Why is node_modules so big?
- Every dependency brings its own dependencies, and each project keeps its own copy, so ten projects can hold ten copies of the same packages. pnpm stores each package version once and links it into projects, which saves space across projects.
Does deleting node_modules clear the npm cache?
- No. npm keeps a separate download cache in ~/.npm on Mac and Linux and %LocalAppData%\npm-cache on Windows. npm cache verify tidies it, and npm cache clean --force empties it.
How do I delete node_modules faster on Windows?
- Use the command line instead of File Explorer: rd /s /q node_modules in Command Prompt, Remove-Item -Recurse -Force node_modules in PowerShell, or npx rimraf node_modules.