npm package.json always get latest version code example

Example 1: update node.js dependencies

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

Example 2: how to update version of dependencies reactjs

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

Example 3: how to install latest version of npm package

//For global packages 
npm i -g @latest
npm i -g express@latest

//For loacal packages
npm outdated
npm update

//Manually updating local packages
npm i @latest
npm update "react" "react-dom"

Example 4: npm get package.json version

node -pe "require('./package.json')['version']"

Example 5: 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 [ | major | minor | patch | premajor | 
preminor | prepatch | prerelease [--preid=] | from-git]

Example 6: package.json version

$(node -pe 'require(\"./package.json\")[\"version\"]')

Tags:

Misc Example