I am hoping to run npm config
to set values in a project's .npmrc file.
Docs dont seem to say how to specify a file to save the values into.
Looking for something like
npm config --file /path/to/repo/.npmrc set key value
Trying to use it for a build script that needs to build a .npmrc file from env vars.
Show activity on this post. Open in it in (for first time users, create a new file) any editor and copy-paste your token. Save it. You are ready to go.
Run npm config ls -l to see a set of configuration parameters that are internal to npm, and are defaults if nothing else is specified.
The config setting for npm is gotten from the command line, environment variables and the npmrc files. You can use the npm config command to update and edit the contents of the user and global npmrc files. Npmrc has four relevant files, they are: The per-project config file (/path/to/my/project/.
It is baffling that this is seemingly still not directly supported as of npm v6.9.0.
It's a bit awkward, but if your npm version is recent enough, you can repurpose the --userconfig
option to make npm config
operate on a project-specific .npmrc
file.
E.g., from a given project's root folder, the following command project-locally configures pwsh
(PowerShell Core) as the shell to run scripts with, by making npm config
operate on the local .npmrc
file via --userconfig
:
# Updates .npmrc in current dir
npm config set script-shell pwsh --userconfig .npmrc
Note: As Kerry Johnson points out:
The target file is rewritten as a whole, in the course of which any comments (#
-prefixed lines) in the original file are lost (but all key-value pairs are preserved).
The config
keyword is optional in this case, so the following will do:
npm set script-shell pwsh --userconfig .npmrc
You can do a chroot
, build your config file on ~/.npmrc
and then copy it on the right location.
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