nvm Global Packages
Manage global npm packages across Node version switches to avoid losing tools like eslint, typescript, or pm2.
Workflow
-
Migrate global packages when installing a new version:
# Install Node 20 and copy global packages from Node 18 nvm install 20 --reinstall-packages-from=18 # Verify packages migrated npm list -g --depth=0 -
Configure default-packages for automatic installation on every new version:
# Create the default-packages file cat > "$NVM_DIR/default-packages" << 'EOF' typescript eslint pm2 nodemon EOF # New installs will auto-install these packages nvm install 22 # typescript, eslint, pm2, nodemon installed automatically -
Verify and validate global packages:
npm list -g --depth=0
Warning: Global packages are version-specific. Switching versions without --reinstall-packages-from means previously installed globals will not be available.
Example file map
examples/migrate-global-packages.md- Migration between versionsexamples/default-global-packages.md- Default packages file setup
Keywords
global packages, default-packages, reinstall-packages-from, npm global, consistency