EDIT:
2022 - March 20th - 20:44 PST
"This edit might not make a whole lot of sense if you have not yet read the original answer below."
This answer will not work for Node.js versions earlier than Node v14.0.0
(the solution works for: ^14.0.0
). This was pointed out in the comments by @jonSakas who was insightful enough to know that the NPM CLI's publish
command, when ran with the following flags, --dry-run --verbose
, as shown here:
npm publish --dry-run --verbose
...does not print the locations of the systems .npmrc
files.
END of EDIT
NPMRC File Locations: The What & Where
NPM configuration files can, and will, exist at different levels in any given environment where Node projects are being developed. As far as I know, there are three specific levels, and they are as follows:
BUILT-IN npmrc
file
GLOBAL npmrc
file
USER'S .npmrc
file.
It Probably isn't Necessary to Know where the Global NPM Config File is.
There are several was you can figure out where the .npmrc
file you are using is at, but you don't need to. For any project you have, stick a .npmrc file in the root directory, right next to ${rootDir}/node_modules/
and ${rootDir}/package.json
. The project-level .npmrc
will override any other NPM files that are altering your project. I have never had NPM alter a project though, unless I changed a configuration file, which meant I knew about the file and where it was. If for some reason though, you still need to find a .npmrc
, and changing the project level .npmrc
document will not help you, you probably don't want to use the raw version of npm config edit
, because that will just configure the project level npm document, and I think it will create one if there is not one, so its essentially does what at suggested at the beginning of the tangent I am on.
Instead, throw a -g into the command, so you you open your global .npmrc
configuration file instead, like this...
npm config -g edit
You it just dawned on me, you actually have another way you can see what configuration files are active. I think this way shows you the file-paths that npm looks at to see if there is an NPM file there or not.
Enter the following...
npm publish --dry-run --verbose
Don't worry if there's no package to publish, or if you have a package to publish, but its not ready to publish. I choose the publish dry-run command because its suppose to not make any changes. And when no package is present, it wont work, but it will still print the logging info you desire. When I did it, it printed the following.
jayd3v@jayd3v-XPS-8910:~$ npm publish --dry-run --verbose
npm verb cli [
npm verb cli '/home/jayd3v/.nvm/versions/node/v17.6.0/bin/node',
npm verb cli '/home/jayd3v/.nvm/versions/node/v17.6.0/bin/npm',
npm verb cli 'publish',
npm verb cli '--dry-run',
npm verb cli '--verbose'
npm verb cli ]
npm info using npm@8.5.2
npm info using node@v17.6.0
npm timing npm:load:whichnode Completed in 1ms
npm timing config:load:defaults Completed in 1ms
npm timing config:load:file:/home/jayd3v/.nvm/versions/node/v17.6.0/lib/node_modules/npm/npmrc Completed in 0ms
npm timing config:load:builtin Completed in 1ms
npm timing config:load:cli Completed in 1ms
npm timing config:load:env Completed in 0ms
npm timing config:load:project Completed in 2ms
npm timing config:load:file:/home/jayd3v/.npmrc Completed in 1ms
npm timing config:load:user Completed in 1ms
npm timing config:load:file:/home/jayd3v/.nvm/versions/node/v17.6.0/etc/npmrc Completed in 0ms
npm timing config:load:global Completed in 0ms
npm timing config:load:validate Completed in 0ms
npm timing config:load:credentials Completed in 0ms
npm timing config:load:setEnvs Completed in 1ms
npm timing config:load Completed in 8ms
npm timing npm:load:configload Completed in 8ms
npm timing npm:load:setTitle Completed in 0ms
npm timing config:load:flatten Completed in 2ms
npm timing npm:load:display Completed in 6ms
npm verb logfile /home/jayd3v/.npm/_logs/2022-03-01T22_15_38_103Z-debug-0.log
npm timing npm:load:logFile Completed in 3ms
npm timing npm:load:timers Completed in 0ms
npm timing npm:load:configScope Completed in 0ms
npm timing npm:load Completed in 19ms
npm verb publish [ '.' ]
You can see that it showed me the three areas that it tried to pull a configuration file ('.npmrc') from. It even named which was which
Built-in npmrc
npm timing config:load:file:/home/jayd3v/.nvm/versions/node/v17.6.0/lib/node_modules/npm/npmrc Completed in 0ms
npm timing config:load:builtin Completed in 1ms
User .npmrc
npm timing config:load:file:/home/jayd3v/.npmrc Completed in 1ms
npm timing config:load:user Completed in 1ms
Global npmrc
npm timing config:load:file:/home/jayd3v/.nvm/versions/node/v17.6.0/etc/npmrc Completed in 0ms
npm timing config:load:global Completed in 0ms