1

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?

Anyul Rivas
  • 655
  • 2
  • 12
  • 31
  • 2
    Possible 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 Answers2

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:

  1. Answer (this code include package.json file and get version)

    const { version } = require('./package.json');


  1. 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