I have the following package.json file:
{
"main": "./dist/index.js",
"scripts": {
"build": "tsc",
"build:live": "tsc && node ./dist/index.js"
},
...
}
How can I get the value of the main field, then put it into the command node ./dist/index.js, something like this (just a example, I know this $ is for ENV variables):
{
"main": "./dist/index.js",
"scripts": {
"build": "tsc",
"build:live": "tsc && node $main"
},
...
}
Thanks in advance
All package.json fields are available as variables by prefixing them with $npm_package_. In your example, you can use this:
{
"main": "./dist/index.js",
"scripts": {
"build": "tsc",
"build:live": "tsc && node $npm_package_main"
},
...
}
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