Categories
Tags
a Accessibility Advanced Algorithms Alias API Design Authentication Bash bash Basics Beginners Best Practices Big O bun cat cd CLI Cloudflare Comments Container Elements Container Queries cp css CSS Data Structures Delta deno DevOps Doctype Download Editors Error Examples Features figure File Watching Filesystem fish Fish Shell footer frontend Guide Hardware Upgrade header Hello World History Homebrew HTML HTML5 humor img javascript JavaScript Laptop Review Learning less Links linux Linux Linux Drivers ls macOS Media Queries meta Mobile-First mv Netcat Networking Node.js npm Open Source Package Manager picture pm2 Privacy Productivity programming Programming pwd Quill Remote Access Responsive Design Responsive Images Rich Text Editor rmdir Runes Scalability section Security Self-hosting Semantic HTML shell Shell Shell Script Shells srcset State Management Structure Svelte Svelte 5 Svelte Store SvelteKit svg Tables tail Tech Journey Text Formatting Tools touch Troubleshooting Tunnel Tutorial TypeScript Ubuntu Unix ux Video Processing Vim web development Web Development web-development webdev WiFi
220 words
1 minutes
How to update all npm packages in multiple projects that sit in subfolders
How to update all npm packages in multiple projects that sit in subfolders
Managing multiple Node.js projects can be challenging, especially when it comes to keeping all npm packages up to date. This guide provides a shell script to update all npm packages in multiple projects located in subfolders.
Shell Script
Here is a simple shell script to update npm packages in all subfolders:
#!/bin/bash
# Loop through each subfolder
for dir in */; do
if [ -d "$dir" ]; then
cd "$dir"
if [ -f "package.json" ]; then
echo "Updating npm packages in $dir"
npm update
fi
cd ..
fi
done
Explanation
for dir in */; do
: This loop iterates over all subfolders in the current directory.if [ -d "$dir" ]; then
: This checks if the item is a directory.cd "$dir"
: This changes the current directory to the subfolder.if [ -f "package.json" ]; then
: This checks if thepackage.json
file exists in the subfolder.npm update
: This updates all npm packages in the subfolder.cd ..
: This changes the directory back to the parent folder.
Running the Script
- Save the script to a file, for example,
update-npm-packages.sh
. - Make the script executable:
chmod +x update-npm-packages.sh
- Run the script:
./update-npm-packages.sh
Conclusion
By using this shell script, you can easily update all npm packages in multiple projects located in subfolders. This can save time and ensure that all your projects are using the latest versions of their dependencies.
How to update all npm packages in multiple projects that sit in subfolders
https://zxce3.net/posts/cli/how-to-update-all-npm-packages-in-multiple-projects-that-sit-in-subfolders/