Categories
Tags
a Accessibility Advanced Algorithms Alias Bash bash Basics Beginners Best Practices Big O bun cat cd CLI Comments Container Elements Container Queries cp css CSS Data Structures deno Doctype Download Editors Error Examples Features figure File Watching Filesystem fish Fish Shell footer frontend Guide header Hello World History Homebrew HTML HTML5 humor img javascript JavaScript Learning less Links linux Linux ls macOS Media Queries meta Mobile-First mv Netcat Networking Node.js npm Package Manager picture pm2 Productivity programming Programming pwd Responsive Design Responsive Images rmdir Scalability section Semantic HTML shell Shell Shell Script Shells srcset State Management Structure Svelte Svelte Store SvelteKit svg Tables tail Text Formatting Tools touch Troubleshooting Tutorial Unix ux Vim web development Web Development web-development webdev
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/