0

I have a package.json file with certain dependencies. One of the dependencies is jquery. The system then downloads the files into the node_modules folder.

How can I get the version of a downloaded dependency from a Javascript file invoked by the node command?

I need to read the equivalent of npm view jquery version in a node JS file?

3
  • 1
    One way would be to require the package.json of the module like so: const pkg = require('./node_modules/{package}/package.json'); console.log(pkg.version); Commented Sep 20, 2017 at 13:22
  • I don't want to read the version of the package json. But I want to read a specific dependency version like what version of JQuery is installed in node_modules. Commented Sep 20, 2017 at 13:23
  • I know, that's exactly what my snippet of code does. Commented Sep 20, 2017 at 13:25

2 Answers 2

3

You can do

console.log(require('jquery/package.json').version);

It will give you the version of the package in your local node_modules.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok super this is it.
0

Try using pkginfo, it should satisfy.

1 Comment

This gives me undefined: var path = require("path"); var fs = require("fs"); var jquery = require("jquery"); return console.log(jquery.version);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.