Skip to main content

A summary of Node package commands

Short cut commands

npm install <package>

npm i <package>

npm install --save <package>

npm i -S <package>

npm install --save-dev <package>

npm i -D <package>

npm install --global <package>

npm i -G <package>

npm test

npm t

 

Update and outdated

Use outdated to discover dependencies that are out of date

npm outdated

Use update to perform safe dependency upgrades

npm update

Use install <packagename>@latest to upgrade to the latest major version of a package

npm install <packagename>@latest

Use npx npm-check-updates -u and npm install to upgrade all dependencies to their latest major versions

npx npm-check-updates -u
npm install

 

 

Install multiple packages in one command

At times there can be a requirement to install multiple packages simultaneously.   Such as when running the command

npm i @capacitor/android@4.8.1

The following was the response

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @angular/common@14.2.12
npm ERR! Found: @angular/core@14.3.0
npm ERR! node_modules/@angular/core
npm ERR!   peer @angular/core@"14" from @asymmetrik/ngx-leaflet@14.0.1
npm ERR!   node_modules/@asymmetrik/ngx-leaflet
npm ERR!     @asymmetrik/ngx-leaflet@"^14.0.1" from the root project
npm ERR!   peer @angular/core@">=12.0.0" from @ionic/angular@6.3.8
npm ERR!   node_modules/@ionic/angular
npm ERR!     @ionic/angular@"^6.2.1" from the root project
npm ERR!   2 more (@ionic/storage-angular, the root project)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"14.2.12" from @angular/common@14.2.12
npm ERR! node_modules/@angular/common
npm ERR!   peer @angular/common@"14.2.12" from @angular/forms@14.2.12
npm ERR!   node_modules/@angular/forms
npm ERR!     peer @angular/forms@">=12.0.0" from @ionic/angular@6.3.8
npm ERR!     node_modules/@ionic/angular
npm ERR!       @ionic/angular@"^6.2.1" from the root project
npm ERR!     1 more (the root project)
npm ERR!   peer @angular/common@"14.2.12" from @angular/platform-browser@14.2.12
npm ERR!   node_modules/@angular/platform-browser
npm ERR!     peer @angular/platform-browser@"14.2.12" from @angular/forms@14.2.12
npm ERR!     node_modules/@angular/forms
npm ERR!       peer @angular/forms@">=12.0.0" from @ionic/angular@6.3.8
npm ERR!       node_modules/@ionic/angular
npm ERR!       1 more (the root project)
npm ERR!     3 more (@angular/platform-browser-dynamic, @angular/router, the root project)
npm ERR!   5 more (@angular/platform-browser-dynamic, @angular/router, ...)
npm ERR!
npm ERR! Conflicting peer dependency: @angular/core@14.2.12
npm ERR! node_modules/@angular/core
npm ERR!   peer @angular/core@"14.2.12" from @angular/common@14.2.12
npm ERR!   node_modules/@angular/common
npm ERR!     peer @angular/common@"14.2.12" from @angular/forms@14.2.12
npm ERR!     node_modules/@angular/forms
npm ERR!       peer @angular/forms@">=12.0.0" from @ionic/angular@6.3.8
npm ERR!       node_modules/@ionic/angular
npm ERR!         @ionic/angular@"^6.2.1" from the root project
npm ERR!       1 more (the root project)
npm ERR!     peer @angular/common@"14.2.12" from @angular/platform-browser@14.2.12
npm ERR!     node_modules/@angular/platform-browser
npm ERR!       peer @angular/platform-browser@"14.2.12" from @angular/forms@14.2.12
npm ERR!       node_modules/@angular/forms
npm ERR!         peer @angular/forms@">=12.0.0" from @ionic/angular@6.3.8
npm ERR!         node_modules/@ionic/angular
npm ERR!         1 more (the root project)
npm ERR!       3 more (@angular/platform-browser-dynamic, @angular/router, the root project)
npm ERR!     5 more (@angular/platform-browser-dynamic, @angular/router, ...)
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! /Users/{name}/.npm/_logs/2023-10-08T00_37_03_088Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/{name}/.npm/_logs/2023-10-08T00_37_03_088Z-debug-0.log

To add multiple packages to one command add a space between each package

npm i {package-01} {package-02} {package-03} ...

As an example

npm i @angular/cli@14.2.13 @angular/common@14.3.0 @angular/compiler@14.3.0 @angular/compiler-cli@14.3.0 @angular/forms@14.3.0 @angular/language-service@14.3.0 @angular/platform-browser@14.3.0 @angular/platform-browser-dynamic@14.3.0 @angular/router@14.3.0 @angular/service-worker@14.3.0 @capacitor/android@4.8.1 @angular-devkit/build-angular@14.2.13 @angular-devkit/core@14.2.13 @angular-devkit/schematics@14.2.13 @ionic/angular@6.7.5

However, note that one misspelled package and the whole command will fail.

In the above example I've managed the versions to be installed.  However, of course this is not required.  The multiple packages could have been

npm i @angular/cli @angular/common @angular/compiler @angular/compiler-cli @angular/forms @angular/language-service @angular/platform-browser @angular/platform-browser-dynamic @angular/router @angular/service-worker @capacitor/android @angular-devkit/build-angular @angular-devkit/core @angular-devkit/schematics @ionic/angular

The difference between the above two commands, the first installs / updates / downgrades to the package version stated.  Whereas, the second command will attempt to install / update to the latest version of each package.

Related articles

Andrew Fletcher18 Mar 2024
Resolving CVE-2022-48624 less issue
To resolve the CVE-2022-48624 vulnerability on Ubuntu using Nginx, it's crucial to understand that the issue lies within the "less" package, not Nginx itself. The vulnerability affects "less" before version 606, where close_altfile in filename.c in less omits shell_quote calls for LESSCLOSE,...