How can I access the name
field from package.json
at runtime?
Is that already stored somewhere or should I open and parse package.json
myself?
If you start your application with npm
, a more robust & more simple approach consists in using process.env.npm_package_name
.
See https://docs.npmjs.com/misc/scripts#packagejson-vars for more information.
It's not stored anywhere by default; the easiest way to load it is probably to just use require
:
require(__dirname + '/package.json').name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With