DEV Community

Discussion on: How To Display App Version in Angular

 
nightwolfdev profile image
nightwolfdev

Correct, there are security implications when importing the whole package.json.

Thread Thread
 
nightwolfdev profile image
nightwolfdev

Another option is to add node to your types property in tsconfig. Then you can use require like the following:

version = require('path/to/package.json').version

Thread Thread
 
halfist profile image
Halfist

But this also exposes package.json to dist, right?

Thread Thread
 
zmrfzn profile image
Zameer Fouzan

On your build pipeline, you could write a custom script that can extract necessary information from package.json and add it to new JSON file e.g. versionInfo.json.
Have the same file checked-in for local dev usage.
You can securely copy this and use this.

Thread Thread
 
halfist profile image
Halfist

Excuse me, but copy what? Did you paste a code snippet I can't see?