Thanks for using Verdaccio to complete NPM private server construction by referring to the article “the most intimate NPM private server construction tutorial in history”.

Building environment:
  • One CLOUD server ECS (instance)
  • The local computer

Local computers use secureCRT to remotely connect (SSH2) cloud server instances

1. Install verdaccio

Install verdaccio globally

[root@iZwz960f904j96nggfchxpZ ~]# npm install -g verdaccio



Create soft chain, otherwise prompt command not found

[root@iZwz960f904j96nggfchxpZ ~]# ln -s ~/ node - v10.15.1 - Linux - x64 /bin/verdaccio /usr/local/bin/



Verdaccio installed successfully

[root@iZwz960f904j96nggfchxpZ ~]# verdaccio -h

Usage: verdaccio [options]



Options:

  -i, --info                  prints debugging information about the local environment

  -l, --listen <[host:]port>  host:port number to listen on (default: localhost:4873)

  -c, --config <config.yaml>  use this configuration file (default: ./config.yaml)

  -V, --version               output the version number

  -h, --help                  output usage information

  

[root@iZwz960f904j96nggfchxpZ ~]# verdaccio -V

4.91.

Copy the code

2. Run verdaccio

[root@iZwz960f904j96nggfchxpZ ~]# verdaccio         

 warn --- config file  - /root/.config/verdaccio/config.yaml

 warn --- Verdaccio started

 warn --- Plugin successfully loaded: verdaccio-htpasswd

 warn --- Plugin successfully loaded: verdaccio-audit

 warn --- http address - http:/ / localhost: 4873 / - verdaccio / 4.9.1

Copy the code

For example, if the system is set up on the local PC, visit http://localhost:4873 to view the NPM package management web page. If the system is set up on the cloud server, Nginx is configured to map port 80 from the Internet to port 4873 from the Intranet

3. Configure nginx

Create verdaccio-nginx.conf in /etc/nginx/conf.d. Create verdaccio-nginx.conf as follows:

upstream verdacciodemo {

Server 127.0.0.1:4873;

    keepalive 64;

}



server {

    listen 80;

Server_name Public IP address or domain name of your server.



    location / {

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;

        proxy_set_header X-Nginx-Proxy true;

        proxy_set_header Connection "";

        proxy_pass http://verdacciodemo;

    }

}

Copy the code
# restart nginx

[root@iZwz960f904j96nggfchxpZ ~]# nginx -s reload

Copy the code

Local PC browser visit http://xxx.xxx.xxx(your cloud server IP), you can see the NPM management page built by Verdaccio, as shown below:


4. Configuration verdaccio

Modify the ~ /. Config/verdaccio/config. Yaml, only changed the packages section, other unchanged, the content is as follows:

.

  

packages:

  '@kuiper/*':

    access: $all

    publish: $authenticated

    unpublish: $authenticated 

  '@ * / *':

    # scoped packages

    access: $all

    publish: $authenticated

    unpublish: $authenticated

    proxy: npmjs

    

.

Copy the code

Added the ‘@kuiper/*’ configuration. If you publish a package with the @kuiper prefix, it is private and will not be proxied externally.

5. Prepare the NPM package

The structure of the NPM package is as follows:


6. Upload the NPM package to the private server

For uploading steps, refer to the instructions on the Verdaccio management page:

# login and create username/password/email

Macbook-pro :~ kuiper$NPM adduser --registry http://your cloud server IP

Username: hello

Password: 

Email: (this IS public) 



# Go to @kuiper/firstdemo and publish the NPM package

Macbook-pro :firstdemo kuiper$NPM publish --registry http://your cloud server IP

npm notice 

NPM notice 📦 @ kuiper/[email protected]

npm notice === Tarball Contents === 

NPM notice 297.9 kB index. Js

npm notice 297B    package.json

npm notice 45B     README.md   

npm notice === Tarball Details === 

npm notice name:          @kuiper/firstdemo                       

NPM notice version 1.0.1

NPM Notice Package Size: 86.7 kB

NPM Notice UNpacked Size: 298.2KB

npm notice shasum:        5b0a9006562241ed4e501cb4acc11905e7c193ee

npm notice integrity: sha512-SragAVP+mldRF[...] 6Ir2FTu0lfgUg==

npm notice total files:   3                                       

npm notice 

+ @ kuiper/[email protected]

Copy the code

7. View the newly uploaded NPM package

Visit http://xxx.xxx.xxx(your cloud server IP), as shown below:

8. Deploy Verdaccio using PM2

The author uses secureCRT to connect to the cloud server. If the terminal window is closed, verdaccio service will not be accessible. Pm2 can solve the above problems.

[root@iZwz960f904j96nggfchxpZ ~]# pm2 start verdaccio

[PM2] Applying action restartProcessId on app [verdaccio](ids: 0)

✓ [PM2] [verdaccio] (0)

[PM2] Process successfully started

┌ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐

│ id  │ name         │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │

├ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤

│ 0 │ verdaccio │ default │ N/A │ fork │ 10825 │ 0s │ 0 │ online │ 21.2 MB │ root │ disabled │

└ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘



# View pM2 managed services

[root@iZwz960f904j96nggfchxpZ ~]# pm2 list

┌ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐

│ id  │ name         │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │

├ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤

│ 0 │ verdaccio │ default │ N/A │ fork │ 11937 │ 0S │ 101 │ online │ 0% │ 76.6 MB │ root │ disabled │

└ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘

Copy the code

9. Install the NPM package on the private server locally

Install the NPM package locally

MacBook-Pro:testKuiper $NPM install @kuiper/firstdemo --registry= http://your cloud server IP address

+ @ kuiper/[email protected]

updated 1 package and audited 2325 packages in8.889 s



75 packages are looking for funding

  run `npm fund` for details



found 0 vulnerabilities

Copy the code

If Not specified, the registry = http://xxx.xxx.xx, will be submitted to the 404 error: Not Found – GET https://registry.npmjs.org/@kuiper%2ffirstdemo – Not Found