How to use verdaccio to create private npm registry?

  1. npm i -g verdaccio
  2. npm set registry http://localhost:4873
  3. verdaccio // to start verdaccio
  4. npm adduser --registry http://localhost:4873
  5. type http://localhost:4873 in bowser adress bar and enter
  6. revise verdaccio config file

    • open a terminal
    • gedit /home/abby/.config/verdaccio/config.yaml
    • add line max\_body\_size: 1000mb in the bottom line. // Set enough large size so that we can publish large package
    • change all access:@all to access:$authenticated
  7. restart verdaccio
    verdaccio
  8. check our current registry
    npm get registry
  9. publish packages in specific registry
    npm publish --registry http://111.11.11.111
  10. remove package if has mistakes
    npm unpublish --force myLibrary

How to start verdaccio with systemd?

  1. find out verdaccio installed path

    npm list verdaccio -g
  2. needs to link node, since I used nvm to install nodejs, or will start verdaccio.service failed and get error: /usr/bin/env: ‘node’: No such file or directory when debug service with journalctl _SYSTEMD_UNIT=verdaccio.service

    sudo ln -s /home/abby/.nvm/versions/node/v13.0.1/bin/node /usr/bin/node
  3. update verdaccio.service, it is in "~/.nvm/versions/node/v13.0.1/lib/node_modules/verdaccio/systemd"

    ExecStart=/home/abby/.nvm/versions/node/v13.0.1/lib/node_modules/verdaccio/bin/verdaccio --config /etc/verdaccio/config.yaml
  4. Copy verdaccio config to etc folder

    sudo cp -RT /home/abby/.config/verdaccio/ /etc/verdaccio/
  5. copy verdaccio.service to /lib/systemd/system/ folder and restart system service

    sudo cp /home/abby/.nvm/versions/node/v13.0.1/lib/node\_modules/verdaccio/systemd/verdaccio.service /lib/systemd/system/ && sudo systemctl daemon-reload

verdaccio config file: config.yaml

# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#

# path to a directory with all packages
storage: /home/abby/.local/share/verdaccio/storage
# path to a directory with plugins to include
plugins: ./plugins

web:
  title: Verdaccio
  # comment out to disable gravatar support
  # gravatar: false
  # by default packages are ordercer ascendant (asc|desc)
  # sort_packages: asc
  enable: true

auth:
  htpasswd:
    file: ./htpasswd
    # Maximum amount of users allowed to register, defaults to "+inf".
    # You can set this to -1 to disable registration.
    # max_users: 1000
  ldap:
    type: ldap
    # Only required if you are fetching groups that do not have a "cn" property. defaults to "cn"
    groupNameAttribute: "ou"
    # Optional, default false.
    cache:
      # max credentials to cache (default to 100 if cache is enabled)
      size: 100
      # cache expiration in seconds (default to 300 if cache is enabled)
      expire: 300
    client_options:
      url: "ldaps://ldap.example.com"
      # Only required if you need auth to bind
      adminDn: "cn=admin,dc=example,dc=com"
      adminPassword: "admin"
      # Search base for users
      searchBase: "ou=People,dc=example,dc=com"
      searchFilter: "(uid={{username}})"
      # If you are using groups, this is also needed
      groupDnProperty: 'cn'
      groupSearchBase: 'ou=groups,dc=myorg,dc=com'
      # If you have memberOf support on your ldap
      searchAttributes: ['*', 'memberOf']
      # Else, if you don't (use one or the other):
      # groupSearchFilter: '(memberUid={{dn}})'
      # Optional
      reconnect: true

# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: https://registry.npmjs.org/

packages:
  '@*/*':
    # scoped packages
    access: $authenticated
    publish: $authenticated
    unpublish: $authenticated
    proxy: npmjs

  '**':
    # allow all users (including non-authenticated users) to read and
    # publish all packages
    #
    # you can specify usernames/groupnames (depending on your auth plugin)
    # and three keywords: "$all", "$anonymous", "$authenticated"
    access: $authenticated

    # allow all known users to publish/publish packages
    # (anyone can register by default, remember?)
    publish: $authenticated
    unpublish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: npmjs

# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:
  keepAliveTimeout: 60

middlewares:
  audit:
    enabled: true

# log settings
logs:
  - { type: stdout, format: pretty, level: http }
  #- {type: file, path: verdaccio.log, level: info}
#experiments:
#  # support for npm token command
#  token: false

# Set enough large size so that we can publish large package
max_body_size: 1000mb

verdaccio.service

[Unit]
Description=Verdaccio lightweight npm proxy registry

[Service]
Type=simple
Restart=on-failure
User=abby
ExecStart=/home/abby/.nvm/versions/node/v13.0.1/lib/node_modules/verdaccio/bin/verdaccio --config /etc/verdaccio/config.yaml

[Install]
WantedBy=multi-user.target

abby_mrs
510 声望12 粉丝