How do I get the current version from package.json using npm
?
I know that npm version
will output my package's version along with npm and other dependencies. But I need a short command to get only my package version to use on a CI. So ideally, no extra input as the CI doesn't know what project it's dealing with.
npm version from-git --allow-same-version
would also work, if it didn't try to tag the new version on Git.
To see the most current version of a package in the npm repository, use the npm view npm get version of package-name version command.
If you want to downgrade npm to a specific version, you can use the following command: npm install -g npm@[version. number] where the number can be like 4.9. 1 or 8 or v6.
The other method is also straightforward, you can check the React app version by heading over to node_modules/react/cjs/react. development. js. You can see the react project version in the commented section as showing given below.
Using npm:
npm -s run env echo '$npm_package_version'
from npm v7.2:
npm pkg get version
There is no direct npm command to show only your package version, but you can use this hack from your project folder:
node -e "console.log(require('./package.json').version);"
If you want to use an npm command you can wrap it into a "script" in your package.json
file :
"scripts": {
"version": "node -e console.log(require('./package.json').version);"
}
Now you can launch npm run version
to get your package version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With