I just want to display the version value of my package.json file within the footer of my app, but have no idea how to do that. I've read you could access those properties with process env object. Is it correct?
Asked
Active
Viewed 1,646 times
1
-
2Possible duplicate of [Is there a way to get version from package.json in nodejs code?](http://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code) – Waiski Oct 04 '16 at 13:52
2 Answers
3
If you're running your app within NodeJs, you can access it by doing
process.env.npm_package_version
With ES6, you can also do
import {version} from './package.json';

Anyul Rivas
- 655
- 2
- 12
- 31
1
The correct answers will be here in example:
Answer (this code include
package.json
file and get version)const { version } = require('./package.json');
Answer
const version = process.env.npm_package_version
Please don't use JSON.parse
, fs.readFile
, fs.readFileSync
and don't use another npm modules
it's not necessary for this question.

аlex
- 5,426
- 1
- 29
- 38