DEV Community

Discussion on: You, me and package.json

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

You might not know this. 🔥

Package JSON files can have internal variables. Anything you place in any field can be referenced to interpolate anything else in your package.json.

$npm_package_{field} where field is a field in the top level. Just add more underscores to drill deeper. I commonly store constants in the config field to cut repetition within package.json AND get values in process env as mentioned in post.

Collapse
 
xabadu profile image
Fernando Larrañaga

I did not know that indeed! That's an awesome tip, thanks for sharing! ✌️

Collapse
 
sidouglas profile image
sidouglas

This won't work in Windows, unfortunately. Need to use cross-var (npmjs.com/package/cross-var)

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

2 / 3 cases, what about Linux subsystem?