Use package.json variable in template


Is it possible to use the version variable of my package.json-file to use it in a template/helper?


On the server, you can do

import {version} from './package.json';

since it is basically a json object!

Furthermore, npm does you one better with package.json vars where the version is available at the npm_package_version environment variable.

Yet these are an should be kept on server side, especially with the import method since you can end up exposing your whole package.json file on the client. It may expose some very sensitive information so be careful.


Ok, I just want to display the current version in a dynamic way. The package.json version variable is been updated on every push to my repository / deploy…
I don’t want to edit any client template manual just to display the version number of the app.

So what would you suggest?


get the version on the server with the json import or env var and send it
down to the client with a custom publication or more preferably a method
call. and then you can include the data in your template.