It is possible to set the global npm config via the global
switch
# short version
npm config set init-version "0.0.1" -g
# long version
npm config set init-version "0.0.1" --global
The location of the global npm config in nvm is tied to node version, rendering it unsuitable for dotfiles
$ npm config get prefix
/home/peterbabic/.nvm/versions/node/v15.4.0
The actual file location is thus
{prefix}/etc/npmrc
^[https://docs.npmjs.com/cli/v6/using-npm/config#globalconfig]
/home/peterbabic/.nvm/versions/node/v15.4.0/etc/npmrc
When installing new node version with nvm, the config file has to be copied over
nvm install 15.4
cp ~/.nvm/versions/node/v14.9.0/etc/npmrc ~/.nvm/versions/node/v15.4.0/etc/npmrc
Not using global setup
Here's how I store npm config among the dotfiles, using so called
userconfig
instead of a global config
- Install nvm
sudo pacman -S nvm
- Install node version of your liking, i.e. stable release^[https://github.com/nvm-sh/nvm#usage]
nvm install stable
- Configure the init values
npm config set init-version "0.0.1"
npm config set init-author-email "[email protected]"
npm config set init-author-name "Peter Babič"
npm config set init-license "MIT"
npm config set init-author-url "https://peterbabic.dev"
Alternatively, paste the values into ~/.npmrc
manually
init-author-name=Peter Babič
init-version=0.0.1
init-author-email=peter@peterbabic.dev
init-license=MIT
init-author-url=https://peterbabic.dev
- Store the file among your dotfiles, i.e. via yadm
yadm add ~/.npmrc && yadm commit
- Initialize the project prompting the values
npm init -y
Produces the pre-configured package.json
file straight away, saving
time
{
"name": "project",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Peter Babič <[email protected]> (https://peterbabic.dev/)",
"license": "MIT"
}
Used versions for the completeness
$ nvm --version
0.35.2
$ npm --version
7.0.15
$ node --version
v15.4.0
$ yay -Qi yadm | grep Version
Version : 2.5.0-1