PJSON is a simple npm package that lets you read the package.json file.
Install it
npm install pjson --save
and use it in your code like this
var pjson = require('pjson');
// simply access values package.json
console.log(pjson.version);
In Node.js you can already import json files by simple giving their names in the require
statements but this approach doesn't always work well.
First of all it's path dependent. So if your project has a nested structure you might end up with code that looks like this
var pjson = require('../../../package.json');
In typescript you cannot create module definitions for relatively imported things. PJSON resolves this issue for you because you can import it just by name
Importing JSON files using require is only enabled in later versions of node. For old versions, PJSON might be useful
It's simple, I needed it for my own project and I though it might be useful for others as well :)