npm install package with version code example

Example 1: install npm globally

npm install npm@latest -g

Example 2: how to install latest version of npm package

//For global packages 
npm i -g <package name>@latest
npm i -g express@latest

//For loacal packages
npm outdated
npm update

//Manually updating local packages
npm i <package name>@latest
npm update "react" "react-dom"

Example 3: install node modules

// Install as a dependency
npm install --save packageName
// OR
npm install --save package1 package2
// OR
npm install --save package@version
// OR
npm i -s packageName

// Install as a dev-dependency
npm install --save-dev package@version
// OR
npm i -D packageName

//Install globally
npm install --global packageName
//OR
npm i -g packageName

// You might need SU access on macos/linux to install globally

Example 4: npm package version

// How to increment your project version
Ex: 1.0.0

* npm version patch ---> 1.0.1
* npm version minor ---> 1.1.0
* npm version major ---> 2.0.0

npm version [<newversion> | major | minor | patch | premajor | 
preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]

Example 5: npm package at version

npm install <package>@<version>