This tutorials explains about installing npm packages on Nodejs and Javascript.

npm install command installs package and it’s dependencies into a node_modules folder. It can be used to install packages locally in a project or globally.

npm install command

Syntax:

npm install package [options]

Options

  • -g: Allows installation on a global location.

nm install yarn -g this will be use full for tools or CLI that need to install global locatin

  • -s or --save: This option allows the installation of package dependencies from package.json, package-lock.json, and npm-shrinkwrap.json.

  • --no-save: Use this option to install the package, in package.json, package-lock.json, and npm-shrinkwrap.json.

  • -d or --save-dev: Enables the installation of devDependencies from package.json, package-lock.json, and npm-shrinkwrap.json.

  • --no-save-dev: Use this option to exclude the devDependencies from installation in package.json, package-lock.json, and npm-shrinkwrap.json.

  • --save-optional or --O: This option changes and update packages under optionalDependencies in all package json files.

npm i is an alias for npm install command

Install previous verson of an package.

Often, there comes a need to downgrade the version of a package that has already been installed in a project.

You can achieve this by using the npm install package@version command.

Firstly, run the command npm list to display the installed packages.

E:\myapp>npm  list
[email protected] E:\myapp
+-- [email protected]

The current installed version of Bootstrap is 5.3.2.

To check the available versions of Bootstrap, run the command npm view bootstrap versions.

npm view is alias for npm show, npm info, and npm vi commands


$npm view bootstrap versions
[
  '0.0.1',         '0.0.2',         '3.1.1',         '3.2.0',
  '3.3.0',         '3.3.1',         '3.3.2',         '3.3.4',
  '3.3.5',         '3.3.6',         '3.3.7',         '3.4.0',
  '3.4.1',         '4.0.0-alpha.2', '4.0.0-alpha.3', '4.0.0-alpha.4',
  '4.0.0-alpha.5', '4.0.0-alpha.6', '4.0.0-beta',    '4.0.0-beta.2',
  '4.0.0-beta.3',  '4.0.0',         '4.1.0',         '4.1.1',
  '4.1.2',         '4.1.3',         '4.2.1',         '4.3.0',
  '4.3.1',         '4.4.0',         '4.4.1',         '4.5.0',
  '4.5.1',         '4.5.2',         '4.5.3',         '4.6.0',
  '4.6.1',         '4.6.2',         '5.0.0-alpha1',  '5.0.0-alpha2',
  '5.0.0-alpha3',  '5.0.0-beta1',   '5.0.0-beta2',   '5.0.0-beta3',
  '5.0.0',         '5.0.1',         '5.0.2',         '5.1.0',
  '5.1.1',         '5.1.2',         '5.1.3',         '5.2.0-beta1',
  '5.2.0',         '5.2.1',         '5.2.2',         '5.2.3',
  '5.3.0-alpha1',  '5.3.0-alpha2',  '5.3.0-alpha3',  '5.3.0',
  '5.3.1',         '5.3.2'
]

You can select a specific version and install it using the following command

npm install [email protected]