bclinkinbeard
bclinkinbeard

Reputation: 110

Read a custom field from package.json synchronously?

I want users of my module to be able to customize its behavior by specifying a custom field in package.json but can't figure out how to read it synchronously. If I wanted to read someField out of the package.json of an app or module using my module, how would I do that?

Upvotes: 1

Views: 1012

Answers (2)

tomdemuyt
tomdemuyt

Reputation: 4592

var pjson = require('./package.json');
console.log(pjson.yourcustomfield);

adopted from another SO question.

Upvotes: 3

Alex Netkachov
Alex Netkachov

Reputation: 13542

Use fs.readFileSync node.js method of the fs module to read the file synchronously.

Upvotes: 1

Related Questions