PJSON
PJSON is a simple npm package that let's you read the package.json file.Usage
Install itnpm install pjson --save
and use it in your code like this
var pjson = require('pjson');
// simply access values package.json
console.log(pjson.version);
Why?
In Node.js you can already import json files by simple giving their names in therequire
statements but this approach doesn't always work well.First of all it's path dependend. So if your project has a nested structure you might endup with a code that looks like this
var pjson = require('../../../package.json');