Roman Saveljev
Roman Saveljev

Reputation: 2594

"node -r package.json" - how to access inside object?

Following some other answer I am trying to retrieve values from package.json.

With "preload" feature I hope to do it like this:

echo 'console.log(???.name)' | node -r package.json

But the ??? bit is missing. What could it be in this case? Thanks.

Upvotes: 1

Views: 97

Answers (1)

Duyet Le
Duyet Le

Reputation: 187

You can try

var package = require('./package.json');

for (var i in package) {
      if (typeof package[i] === 'object' && package[i].hasOwnProperty("name"))
          console.log(package[i].name)
}

Upvotes: 1

Related Questions