Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 302 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find the version of an installed npm package

#11
Use

```lang-none
npm info YOUR_PACKAGE version
```

E.g.,

```lang-none
npm info grunt version

0.4.5
```
Reply

#12
I just used

npm list | grep <package name>

and it worked great.

On Windows, run:

npm list | find <package name>

In [PowerShell][1] run:

npm list | sls <package name>

[1]:

[To see links please register here]

Reply

#13
If you agree to install [jq](

[To see links please register here]

), you can use the JSON output of `npm list`:

```lang-none
npm -j ls <package-name> | jq -r .version
```

Or, if you want to be verbose:

```lang-none
npm --json list <package-name> | jq --raw-output '.version'
```

For instance:

```lang-none
npm -j ls ghost | jq -r .version
```

Output:

```lang-none
0.4.2
```

Also, the JSON format is slightly different for global packages, so you'll need to change the query.

For instance:

```lang-none
npm -j -g ls | jq -r .dependencies.ghost.version
```

Output:

```lang-none
0.4.2
```

Reply

#14
Here's a portable Unix (using `grep` and `sed`) one-liner that returns the version string of a globally-installed npm package (remove the `g` from `-pg` to query local packages instead):

```lang-none
npm ll -pg --depth=0 grunt | grep -o "@.*:" | sed 's/.$//; s/^.//'
```

Output:

```lang-none
0.4.5
```

- the `npm ll` outputs a parsable string formatted like: `/usr/lib/node_modules/npm:[email protected]:`;
- the `grep` command extracts the value between `@` and `:`, inclusive;
- the `sed` command removes the surrounding characters.



Reply

#15
You can use *npm view [module] version*, *npm info [module] version*, *npm show [module] version* or *npm v [module] version* to check the version on an installed npm module.

Let's suppose my [Grunt][1] module version is the 0.4.5:

```lang-none
npm view grunt version => 0.4.5
npm info grunt version => 0.4.5
npm show grunt version => 0.4.5
npm v grunt version => 0.4.5
```

[1]:

[To see links please register here]



Reply

#16
Try with:

```lang-none
npm list --depth 1 --global packagename
```

Reply

#17
If you are brave enough (and have Node.js installed), you can always do something like:

echo "console.log(require('./package.json').version);" | node

This will print the version of the current package.
You can also modify it to go insane, like this:

echo "eval('var result='+require('child_process').execSync('npm version',{encoding:'utf8'})); console.log(result.WHATEVER_PACKAGE_NAME);" | node

That will print the version of `WHATEVER_PACKAGE_NAME` package, that is seen by `npm version`.



Reply

#18
From the root of the package do:

node -p "require('./package.json').version"

(So you need to `cd` into the module's home directory if you are not already there. If you have installed the module with `npm install`, then it will be under `node_modules/<module_name>`.)




Reply

#19
I added this to my [.bashrc][1] file:

function npmv {
case $# in # Number of arguments passed
0) v="$(npm -v)" ; # Store output from npm -v in variable
echo "NPM version is: $v"; # Can't use single quotes
# ${v} would also work
;;
1) s="$(npm list --depth=0 $1 | grep $1 | cut -d @ -f 2)";
echo "$s";
;;
2) case "$2" in # Second argument
g) #global| # Syntax to compare bash string to literal
s="$(npm list --depth=0 -g $1 | grep $1 | cut -d @ -f 2)";
echo "$s";
;;
l) #Latest
npm view $1 version; # 'npm info $1 version' does the same thing
;;
*) echo 'Invalid arguments';
;;
esac;
;;
*) echo 'Invalid arguments';
;;
esac;
}
export -f npmv


Now all I have to do is type:

- **npmv** for the version of npm, for example, `NPM version is: 4.2.0`
- **npmv <package-name>** for the local version, for example, `0.8.08`
- **npmv <package-name> g** for global version, for example, `0.8.09`
- **npmv <package-name> l** for latest version, for example, `0.8.10`

Note *-d* on the *cut* command means delimit by, followed by @, and then f means field. The '2' means the second field since there will be one either side of the *@* symbol.

[1]:

[To see links please register here]





Reply

#20
Combining some of the above answers and produces a super simple and super quick lookup.

Run from the project root. There isn’t any need to `cd` into any folder, just one line:

`node -p "require('SOMEPACKAGE/package.json').version"`

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through