Woah, just learned that in Node, values in package.json are automatically...


Woah, just learned that in Node, values in package.json are automatically accessible like this:

process.env.npm_package_keyYouWantHere

For example, if you want to read the version key from package.json in your Node script, do this:

process.env.npm_package_version
That said, I typically prefer to import package.json when I want to reference values from it. It's more explicit. The trick above works, but I just saw someone doing it and was very confused about where that global came from until they explained it to me. 😂

View original on X