npm publishing package process

when you want to publish a package to a specific registry, you have to login to that registry first or have a token handy. lets look at logging in first

npm login --registry=registry.selectiont.com

after putting in your user name and password, they will assign you a token and place it in /{user}/.npmrc (/root/.npmrc) will be altered

now you can publish packages to this registry

to skip logging in and place the regestry and token in /{user}/.npmrc

npm config set -- "//registry.selectiont.com:_authToken" "$VERDACCIO_TOKEN"

with gitlab things are a-little different. Each project has its on registry. so when you publish you have to specify that registry.

 npm config set -- "//gitlab.selectiont.com/api/v4/projects/{project id}/packages/npm/:_authToken" "$GITLAB_TOKEN"

{project id} being

the code above writes to /{user}/.npmrc

npm config set registry "http://registry.selectiont.com"

this code above changes the default registry.

in writing the code above before publishing a package, you skip the step of having to place the code below inside of your package.json of the package you are publishing

"publishConfig":{
  "registry": "https://gitlab.com/api/v4/projects/<your-project-id>/packages/npm/"
}

this field tells gitlab to run this line

npm config set registry "http://registry.selectiont.com"

prior to publishing.

Leave a Reply

Your email address will not be published.