1

I was wondering is there a way to extract and print version information of all dependencies? For example I am using following dependencies:

"dependencies": {
    "angular2": "2.0.0-beta.15",
    "bu-controls": "^0.0.34",
    "es6-shim": "^0.35.0",
    "jquery": "^2.2.0",
    "moment": "2.14.1",
    "ms-signalr-client": "2.2.5",
    "ng2-translate": "^1.11.1",
    "numeral": "1.5.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "systemjs": "~0.19.18",
    "underscore": "1.8.3",
    "zone.js": "0.6.10"
  }

So my task is to display version information on the browser for the clients. Thank you very much, in advance, for your help.

4
  • Is it going to need to be on demand? As in the user clicks a button and then the dependencies show up?
    – Scrambo
    Commented Aug 15, 2016 at 12:15
  • I am going to have a page, there all the dependencies will be displayed in a table.
    – Bahodir
    Commented Aug 15, 2016 at 12:18
  • just deploy json with dependencies and use it
    – Aleksey L.
    Commented Aug 15, 2016 at 12:20
  • 1
    Thanks Aleksey, wanted to avoid deploying package.json, if you meant that.
    – Bahodir
    Commented Aug 15, 2016 at 12:25

1 Answer 1

9

Since you're using npm, you can redirect the output of the command npm list --depth=0 to a file, and then parse the file and display the contents on your webpage in the browser.

Here's an example of what npm list --depth=0 looks like in a project of mine.

+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected] invalid
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
3
  • Thank you for your reply, in this way will I always depend on updating the list file (file created after npm list --depth=0)? I mean, if version of some lib has been changes, to display it the list file has to be updated.
    – Bahodir
    Commented Aug 15, 2016 at 12:31
  • Yes that would be correct, any time you updated any dependencies the file would have to be updated to match the new version. This could be mitigated by making a new file every time a user goes to this dependency page, though I'm not sure if that's something that you'd want or be willing to do.
    – Scrambo
    Commented Aug 15, 2016 at 12:34
  • Ok, thanks, I will add a script that is triggered each time when npm install is run. This way I hope to update the list file each time when npm i is run.
    – Bahodir
    Commented Aug 15, 2016 at 12:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.