Post #2172103
2024-01-07 15:36 UTC
Using variables in npm run scripts (package (a)rauschma/env-var must be installed locally or globally):
{
"scripts": {
"hi": "env-var echo {{npm_package_config_hi}}"
},
"config": {
"hi": "HELLO"
}
}
Works on Windows and Unix:
npm run hi
More information: https://exploringjs.com/nodejs-shell-scripting/ch_package-scripts.html#using-environment-variables-in-package-scripts
#NodeJS
Replies (2)
-
@brawaru@mstdn.social 2024-01-07 16:09
@rauschma@fosstodon.org if you are using pnpm, there's `shell-emulator` configuration option: https://pnpm.io/cli/run#shell-emulator. It lets you `DEFINE_ENVS=before script` like you'd do in regular POSIX shell. Yarn does use it by default. Kinda wish npm adopted that (probably as an option, to stay backwards compatible).
-
@whiteja@mastodon.social 2024-01-08 19:53
@rauschma@fosstodon.org Hello, is that the env-var package from the npmjs registry? I thought I'd give the example a try since it would help me out, but I get an error that there's no env-var command found. This is with that npm package installed either locally or globally, and I'm curious if I've got the right one.