Set up steps
  1. First of all, we need to apply for a Linux server from the operation and maintenance students. A virtual machine of about 2GB is enough.
  2. Find a suitable place to download and install NodeJS, such as in/usr/local/libUnder the

    Install wget:yum install -y wget; (Skip this step for those already installed.)

    Download:Wget HTTP: / / https://nodejs.org/dist/v10.6.0/node-v10.6.0-linux-x64.tar.xz;

    Extract:The tar XVF - node - v10.6.0 - Linux - x64. Tar. Xz;

    Rename the installation directory:Node - mv v10.6.0 - Linux - x64 nodejs;

    Establish soft connection:

    ln -s /usr/local/lib/nodejs/bin/npm /usr/local/bin/

    ln -s /usr/local/lib/nodejs/bin/node /usr/local/bin/
  3. performnode -vandnpm -vCommand to check whether the installation succeeds
  4. Global installation verdaccio:npm i verdaccio -g;
  5. Install pM2 globally, which is used to guard node processes:npm i pm2 -g;
  6. Install nginx, still in/usr/local/libUnder the

    Download:Wget HTTP: / / http://nginx.org/download/nginx-1.13.7.tar.gz

    Extract:The tar - ZXVF nginx - 1.13.7. Tar. Gz;

    Change the name:The mv nginx - 1.13.7 nginx;

    Go to the installation directory:cd nginx

    Perform:./configure;

    Perform:make && make install;

    cd conf/Modify nginx.conf and add this paragraph:

server { listen 80; server_name registry.npm.your.server; Location / {proxy_pass http://127.0.0.1:4873/; proxy_set_header Host$host; }}Copy the code

Soft connections: ln -s/usr/local/nginx/sbin/nginx/usr/local/bin/nginx start: sudo nginx (restart command: sudo nginx -s reload)

  1. Pm2 Starts the servicepm2 start verdaccioAnd then the browser visitshttp://server IP addressIf the following page is displayed, the installation is successful.

    image.png

Usage of Verdaccio

Verdaccio allows anyone to create an account, and by default any development registered with Verdaccio has publish permission if the verdaccio configuration file config.yaml is not configured. Here’s an example:

  1. Add a user: NPM adduser –registry http://172.16.14.5:

    image.png

  2. To add source information to the project you want to add to the service, create a new.npmrc file under the project root directory and add the following:

Registry = http://172.16.14.5/Copy the code

  1. package.jsonAfter the version is set, runnpm publish:

image.png

At this point, visit http://172.16.14.5 and the project appears in the list:

image.png

Verdaccio Best practices

The steps for the publish repository above are simple: create user -> set NPM source -> NPM publish. But that’s not the flow we want, we want publish permissions to control, and that’s certainly possible.

Yaml config file is usually in/create user /.config/verdaccio. If you are not sure, you can directly run verdaccio command on the server. The first config file is where the file is located.

image.png

There are two files and a directory in this directory:

image.png

Open config.yaml and view the packages TAB, which originally reads:

packages:
  '@ * / *':
    # scoped packages
    access: $all
    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: $all

    # 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

Copy the code

Scope has two modes: @/ indicates a project under the scope and * matches the project name (the name is defined in package.json).

  • access: indicates which type of user can install the matching project.
  • publish: indicates which type of user can publish matching items
  • proxyThe value is corresponding to the uplinks name. If the local uplinks name does not exist, the corresponding Uplinks name is allowed.

Meaning of value:

  • $allAll users (registered and unregistered) can perform corresponding operations
  • $authenticatedThis means that only authenticated people (registered) can perform the corresponding operation. Note that anyone can register an account.
  • $anonymousIndicates that only anonymous users can perform corresponding operations (usually useless)

If you want to specify a specific user, you can write the user name and separate multiple users with Spaces, for example:

publish: michael martin
Copy the code

After the modification, restart nginx and PM2. The list of existing users can be viewed in the htpasswd file.

Download packages and cache repositories

For projects that specify the source as the Intranet source, you can download the Intranet library through NPM install. Our internal repository is stored in the storage directory. If you enter the storage directory, you can see that it stores the libraries we have used:

image.png

Testpro is our internal library, and when you go into the library, you can see that all of our releases are stored here as compressed packages


image.png

reference
  1. Ways to have your private npm registry
  2. Verdaccio.org/docs/en/wha…





Author: LK2917


Link: https://www.jianshu.com/p/d32ce7e9d4d8


Source: Jane Book


Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please indicate the source.