Skip to content

NPM

Common commands

bash
npm install <package> --save|--global
npm uninstall <package>

Gitlab NPM Registry

Authenticate

Personal access token

  1. Go to gitlab user account > Access Tokens
  2. Add a new token with api access and save
  3. Copy and save the token
  4. Set authentication
sh
npm config set -- "//gitlab.example.com/api/v4/packages/npm/:_authToken" "<token>"

Scope

Scope will be the root of your gitlab. For example: https://gitlab.com/jckoh/software-v2/lib/logger

The scope will be jckoh

Library development

  1. Create empty directory
  2. Initialize npm project and fill in required information, for package name, follow gitlab documentation Package Naming Convention
sh
npm init
  1. Create .npmrc at project directory
  2. Configure npm registry
sh
npm config set @<scope>:registry https://gitlab.com/api/v4/projects/<project_id>/packages/npm/

npm config set -- '//gitlab.com/api/v4/projects/<project_id>/packages/npm/:_authToken' "<token>"
  1. Publish your npm using
sh
npm publish
  1. You also can define your publish config at package.json.
json
{
    "publishConfig": { "@<scope>:registry":" https://gitlab.com/api/v4/projects/<project_id>/packages/npm/" }
}

Using private npm

  1. Set the scope
sh
npm config set @<scope>:registry https://gitlab.com/api/v4/packages/npm/
  1. Install npm package
sh
    npm install @scope/package

publish to npmjs.com public repository

  1. Init
sh
npm init --scope=@scope-name
  1. Publish
sh
npm publish --access public

Pnpm

Workspace

TODO

pnpm add file:<path to library>

# At library you want to share
pnpm link 

# At project want to use library
pnpm link <pkg>