Summary of building and using NPM private warehouse based on verdaccio



  • Official:
  • Reference:
  • Reference:
  • Reference:

The original private service was built by sinopia, but sinopia stopped maintenance for two years, now it is verdaccio. It’s also super simple to use verdaccio. It only takes a few minutes to build a private server, which is suitable for the internal and external package installation of the company

1: Installation and configuration

A. installation

$ yarn global add verdaccio
yarn global v1.12.3
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "[email protected]" with binaries:
      - verdaccio
Done in 52.10s.

Installed to theC:\Users\Administrator\AppData\Local\Yarn\bin[my is win10]

ornpm install --global verdaccioinstall

B. test

Create an empty directory test. My current working directory isF:\youshengyouse\del3

$ verdaccio
 warn --- config file  - C:\Users\Administrator\.config\verdaccio\config.yaml
 warn --- Plugin successfully loaded: htpasswd
 warn --- Plugin successfully loaded: audit
 warn --- http address - http://localhost:4873/ - verdaccio/3.10.1

Enter in browserhttp://localhost:4873/, the results are as follows
Summary of building and using NPM private warehouse based on verdaccio

2: Add user

Open another command line window. The original verdaccio is still running

$ npm adduser --registry  http://localhost:4873
Username: abcd
Password: qwer
Email: (this IS public) [email protected]
Logged in as abcd on http://localhost:4873/.

3: Release private package

Current working directory:Which package to publish? Switch the current directory to the package root directory

$ npm publish --registry http://localhost:4873

> [email protected] prepare .
> cross-env NODE_ENV=production npm run build

> [email protected] build F:\youshengyouse\frontend\packages\gatsby\packages\gatsby2-cli
> babel src --out-dir lib --ignore **/__tests__

Successfully compiled 6 files with Babel.
npm notice
npm notice package: [email protected]
npm notice === Tarball Contents ===
npm notice 1.8kB package.json
npm notice 7.4kB
npm notice 3.3kB
npm notice 9.4kB lib/create-cli.js
npm notice 2.7kB lib/index.js
npm notice 4.7kB lib/init-starter.js
npm notice 2.0kB lib/reporter/errors.js
npm notice 3.1kB lib/reporter/index.js
npm notice 4.0kB lib/reporter/prepare-stack-trace.js
npm notice === Tarball Details ===
npm notice name:          gatsby2-cli
npm notice version:       1.0.0
npm notice package size:  11.0 kB
npm notice unpacked size: 38.3 kB
npm notice shasum:        64c9c47b81610731e559bc33f86aa02f87155656
npm notice integrity:     sha512-vhroNpnWCwivE[...]8hAg+z6SPOeyw==
npm notice total files:   9
npm notice
+ [email protected]

Refresh nowhttp://localhost:4873/#/You can see the package just released
Question:Where are the locally installed packages?

4: Installation package

npm set registry http://localhost:4873/

View warehouse

npm config get registry
$NPM init ා if there is no package.json file, you need to create it first
$ yarn add gatsby2-cli

It is found that gatsby2 cli is local, and other dependencies are installed from warehouse


Problem 1: too much space. Find a solution. The global cache is on disk C
Solution: reconfigure NPM
The configuration file for NPM isC:\Users\Administrator\.npmrc

See configuration

$ npm config list
; cli configs
metrics-registry = ""
scope = ""
user-agent = "npm/6.4.1 node/v10.15.0 win32 x64"

; builtin config undefined
prefix = "C:\\Users\\Administrator\\AppData\\Roaming\\npm"

; node bin location = E:\Program Files\nodejs\node.exe
; cwd = F:\youshengyouse\del3
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

Modify prefix toE:\Program Files\nodejs

#Modify cache address
$ npm config set cache "E:\Program Files\nodejs\node_cache2019"
#Modify global placement
$ npm config set prefix "E:\Program Files\nodejs"

Now the configuration is as follows

$ npm config list
; cli configs
metrics-registry = "http://localhost:4873/"
scope = ""
user-agent = "npm/6.4.1 node/v10.15.0 win32 x64"

; userconfig C:\Users\Administrator\.npmrc
ca = null
cache = "E:\\Program Files\\nodejs\\node_cache2019"
prefix = "E:\\Program Files\\nodejs"
registry = "http://localhost:4873/"

; builtin config undefined

; node bin location = E:\Program Files\nodejs\node.exe
; cwd = F:\youshengyouse\frontend\packages\gatsby\www
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

Global installation

$ npm i -g gatsby-cli
E:\Program Files\nodejs\gatsby -> E:\Program Files\nodejs\node_modules\gatsby-cli\lib\index.js
+ [email protected]
added 211 packages from 119 contributors in 121.998s

Will be installed inE:\Program Files\nodejs\node_modules\gatsby-cliAt the same timeE: \ program files \ nodejs \ Gatsby and gatsby.cmdTwo shell commands are also installed at the same time
Configure environment variablesE:\Program Files\nodejs\node_modules, so that it can be executed globally anywheregatsby

Restore official warehouse

npm config set registry