npm install package latest version code example

Example 1: use npm to update packages to latest version

npm i -g npm-check-updates
ncu -u
npm install

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 an npm package

npm install package-name

To save as a dependency:
npm install package-name --save