Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inspect package.json from command line

Tags:

node.js

npm

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?

like image 461
Rob Wilkerson Avatar asked Nov 19 '25 05:11

Rob Wilkerson


1 Answers

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
like image 160
Gökay Gürcan Avatar answered Nov 21 '25 22:11

Gökay Gürcan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!