Rob Wilkerson
Rob Wilkerson

Reputation: 41256

Inspect package.json from command line

This seems like it should/would be simple and possible, but I haven't found the magic commands. I'm sitting at the command line in a given directory that has a package.json file. What I'd like to do is execute a simple command to read the version value in that file. Is that possible?

$ npm version
{ 'my-project': '6.5.0',
  npm: '2.12.1',
  http_parser: '2.3',
  modules: '14',
  node: '0.12.7',
  openssl: '1.0.1p',
  uv: '1.6.1',
  v8: '3.28.71.19',
  zlib: '1.2.8' }

All I'm after in this case is the value of my-project. Possible?

Upvotes: 3

Views: 2017

Answers (1)

Gökay Gürcan
Gökay Gürcan

Reputation: 1094

If I understand you correctly, you want something like this:

node -e 'console.log(process.versions)'
{ http_parser: '2.5.0',
  node: '4.0.0',
  v8: '4.5.103.30',
  uv: '1.7.3',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  modules: '46',
  openssl: '1.0.2d' }

and this:

node -e 'console.log(require("./package.json").version)'
1.2.3

Upvotes: 6

Related Questions