One, foreword

Many times, companies may not want to open source their code for security, privacy or other reasons, so they build their own private repositories. Currently, the common front-end package manager is the public repository of NPM. Since the department currently uses Nexus2 to manage back-end JAR packages, it uses Nexus2 to build the NPM private repository.

2. Set up the Nexus2 private warehouse

Build process is omitted (specific reference: blog.csdn.net/xixiaoxie2/…).

The nexus2 supports three types of private libraries

  • Proxying NPM Registries proxy repository

The warehouse can remote access to public warehouses, the current setting of the register to https://registry.npm.taobao.org

The server caches downloaded packages.

Only packages from public repositories can be downloaded.

  • Private NPM Registries managed repository

The repository is a private repository and can publish its own code packages and download packages already published in the private repository.

  • Grouping NPM Registries repository group

By combining the first two separate repositories, you can download packages from both the public repository and the private repository.

Use a private repository for local configuration

After the private warehouse is built, we can use the warehouse, before using, we need to configure a wave.

First, we register a private warehouse account



Then assign permissions. This operation is best performed by the highest permission account admin.

Then use NPM config ls to view the NPM configuration

If not configured
registerBy default,
http://registry.npmjs.org

Register and Registry can be ignored and are described later.



There’s one in the figure above
HOMETo see the
HOMEIs there one under the path
.npmrcThe configuration file
If no, manually create one
And then edit.
npmrcfile
You can use Notepad to open direct editing, or you can open terminal, command editing, and I chose command editing

npm config setEmail "[email protected]" NPM configset always-auth true

npm config set _auth "ROY***********=="Copy the code

Note here:
email Is the mailbox bound to the login user
_auth It’s for the username and password
base64The code format is user name: password

4. Release private repository on code package:

When publishing a private package,
npmthe
registryNeed to change to the path you publish
Can be modified permanently, can be modified temporarily, see personal interest
Temporary changes are made at the time of release
npm publishadd
registryOption or when you need to publish the package
package.jsonConfiguration in file



To publish a module, you must ensure that the package.json file is in the root directory, otherwise an error will be reported
And it is recommended to include it in the distribution package
  • package.json
  • index.js
  • REDME.md
Three files
package.jsonthrough
npm initInitialize out



Permanent modification is
NPM config set registry
Then it’s ready to publish



Once published, it can be downloaded when needed…

Download packages from a private repository

The downloading of private library is much the same as uploading of private library
Need to modify
npmthe
registerconfiguration
This, like publishing, can be changed permanently or temporarily
Same steps as publishing.
Temporary modification, each time download, bring the path of the package to download, and the name of the package.



It can also be modified permanently:

npm config set -register "http://****"Copy the code

And then when you download it, you just need the -register parameter

npm -loglevel info install testCopy the code



If you want to undo a published package, you can do it directly on the Nexus. Hee hee!

Here you can enjoy the use of the company’s internal private storage ~

This article reference www.cnblogs.com/wfeicherish…

And finally… Novice on the road, will inevitably bump bump, if where write bad or careless, welcome to point out at any time, learn together.

Come on!!