0

How do I find the exact installed version of a package from package.json in an express application in a Fedora distribution?

I could look through package-lock.json but are there an easier way, as it's huge?

I've tried

npm list

but it's not installed and I don't want to install it if is not necessary.

Any easy way of doing this?

3 Answers 3

0

For NPM to get a list of package versions you must first cd to the folder where your NPM application is.

Then run (from folder where you run your npm apps)

npm ls --depth=0 

If you dont see anything try the command with global setting

npm -g ls --depth=0
1
  • I do need to install npm on the server then as I get -bash: npm: command not found when running above command. I'm looking for a way to not have to install npm as its and elastic beanstalk that "resets" it self when i rebuild it/scale it. Commented Mar 5, 2020 at 7:16
0

The following script searches the package.json file in the directory where it is executed for the specified package and prints out its version:

# getPackageVersion.sh
# Searches the package.json for a specific package and prints out its version
#
# Usage:
# chmod +x getPackageVersion.sh
# ./getPackageVersion.sh <package_name>

packageName=$1

if [ ! -f ./package.json ]; then
    echo "package.json file not found in current directory."
    exit
fi

if [ -z "$packageName" ]
then
    echo "No package name given."
    exit
fi

packageJsonOutput=$(cat package.json | grep "\"$packageName\": \"*\"")
version=(${packageJsonOutput//:/ })
version=${version[1]//\"/}

if [ "$version" == "" ]
then
    echo "Package not found."
    exit
fi

echo "$version"

Usage

chmod +x getPackageVersion.sh
./getPackageVersion.sh <package_name>

Example

$ cd ~/sw/your-project/
$ ./getPackageVersion.sh debug
4.3.1
0

if you use yarn as package manager, yarn.lock contains the exact version that is resolved during yarn install command run.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.