cnpmjc and sinopia build private warehouse

cnpmjc and sinopia build private warehouse

Article directory

Basic use of nrm

nrm is the abbreviation of npm registry manager. it is a module that manages the npm mirror address separately. note that it manages the mirror address. the list is all the mirror address corresponding to the name. you can use the nrm command to quickly switch the npm mirror address.

install

npm install nrm -g

Use

View Named nrm --help or nrm-h

Commands:

  ls                           List all the registries
  current                      Show current registry name
  use <registry>               Change registry to registry
  add <registry> <url> [home]  Add one custom registry
  del <registry>               Delete one custom registry
  home <registry> [browser]    Open the homepage of registry with optional browser
  test [registry]              Show response time for specific or all registries
  help                         Print this help

There are queries, additions and deletions, test commands

nrm ls

Result

 npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/
  local -- http://192.168.1.243:7001/

The key to name-value is name and mirror address value. Name is just name, not the corresponding mirror address of cnpm is the corresponding address of cnpm command. Instead, nrm provides so many mirror addresses for npm to use. * Number indicates the mirror address currently in use. For example, the operation corresponding to the mirror name local.
Switch address: nrm use local
Add address: nrm add local http://192.168.1.243:7001
Delete address: nrm del local

npm, cnpm set mirror

Take setting Taobao image as an example https://registry.npm.taobao.org/

npm config set registry https://registry.npm.taobao.org/
cnpm config set registry https://registry.npm.taobao.org/

The above name sets the registration mirror address of the corresponding module. If we use nrm ls at this time, the results are as follows:

 npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/
  local -- http://192.168.1.243:7001/

Currently (* pointing) uses the name taobao mirror address.
So we can use the nrm module to switch between different images, or we can set the registered image addresses of npm and cnpm directly by naming.

cnpmjs.org Server installation steps

github official website

Clone code

cd D:\cnpmjs(Create without)
git clone https://github.com/cnpm/cnpmjs.org.git
cd cnpmjs.org

Install mysql database

Create a new database cnpmjs locally, find db.sql in the docs directory of source code, and execute SQL file under cpmjs. The results are as follows:

Configure config/index

Back up an index.js
Open index.js

Database Configuration

 database: {
    db: 'cnpmjs',
    username: 'root',
    password: 'root',

    // the sql dialect of the database
    // - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb'
    dialect: 'mysql',

    // custom host; default: 127.0.0.1
    host: '127.0.0.1',

    // custom port; default: 3306
    port: 3306,

    // use pooling in order to reduce db connection overload and to increase speed
    // currently only for mysql and postgresql (since v1.5.0)
    pool: {
      maxConnections: 10,
      minConnections: 0,
      maxIdleTime: 30000
    },

    // the storage engine for 'sqlite'
    // default store into ~/.cnpmjs.org/data.sqlite
    storage: path.join(dataDir, 'data.sqlite'),

    logging: !!process.env.SQL_DEBUG,
  },

Other configurations

Support for Extranet Access

Change bindingHost:'127.0.0.1'to bindingHost:'0.0.0',

Increase Administrator Account

admins: {
    // name: email
    fengmk2: 'fengmk2@gmail.com',
    admin: 'admin@cnpmjs.org',
    dead_horse: 'dead_horse@qq.com',
	chenyuan:'chenyuan122912@sina.com',
	cy:'chenyuan@sina.com'
  },
registryHost: '127.0.0.1:7001',

Note that only name and mailbox are required above and no password is required. The password is set at the time of initial login. That is to say, when cnpm login prompts you to enter a password, the first password you enter is the closest one.

Only administrators can publish packages

Change enablePrivate: false to enablePrivate: true,

start-up

cnpm provides two ports: 7001 and 7002, 7001 for NPM registration services and 7002 for Web access.

node dispatch.js

Verification

So far, the server has been configured.

cnpmjs.org client

Configure registry of npm

  1. Method 1
npm set registry http://localhost:4873
  1. Method two
    Using nrm, there are instructions on how to use it
nrm add local http://127.0.0.1:4873
nrm use local

Release

npm login
...Enter username and password after success...
npm publish

The results are as follows:

The specified module can only be found through the search box. It's not good that you can't browse all of them.

Siopia Builds Private Warehouse

github address
Building internal npm services with sinopia
Build a private cached npm server, no database, 0 configuration.
Using the file system as storage, only the packages needed by the user are saved. If there are no corresponding packages in the local warehouse, they are downloaded from the specified registry. Default npmjs.org It can be changed into Taobao's mirror image.

python installation

sinopia needs python support
Installation steps

Installation and start-up

Installation: NPM I sinopia-g
Start: sinopia

The config.yaml file directory will be generated on the c disk as follows
C:\Users\Administrator\AppData\Roaming\sinopia
The list of documents is as follows:
storage: storage Path
htpasswd: Save password information only after new users have created this file
config.yaml: This is the local configuration file information (change this)

Modify configuration

Make LAN accessible
Modify C: Users Administrator AppData Roaming sinopia config. yaml and add the following:

listen: 0.0.0.0:4873 

The complete configuration is as follows

#
# 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/rlidwka/sinopia/tree/master/conf
#

# path to a directory with all packages
storage: ./storage    # npm Packet Storage Path

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
    max_users: 1000     # Default 1000, changed to - 1, prohibit registration

# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: http://Regisry. npm. taobao. org/ # defaults to the official network of npm. Because of the national conditions, modify the url to allow sinopia to use the NPM mirror address of Taobao.

packages:
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated

  '*':
    # 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 packages
    # (anyone can register by default, remember?)
    publish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    # proxy: npmjs   #If this is removed, sinopia will not download dependency packages if it just wants to put it in its own repository.      
    # 

# log settings
logs:
  - {type: stdout, format: pretty, level: http}
  #- {type: file, path: sinopia.log, level: info}

# you can specify listen address (or simply a port) 
listen: 0.0.0.0:4873  # By default, it can only be accessed locally, and can be accessed through the external network after adding.

New user

npm adduser
Username: test
Password: test
Email: (this IS public) xxx@xxxx

Configure registry of npm

  1. Method 1
npm set registry http://localhost:4873
  1. Method two
    Using nrm, there are instructions on how to use it
nrm add local http://127.0.0.1:4873
nrm use local

Note that this can only switch npm work, not cnpm. If you want to modify cnpm, you can only switch through cnpm set registry http://localhost:4873

Release

npm publish     // Make this command in the package path you want to publish

give the result as follows

What packages can be browsed directly, unlike cnpmjs, only the total number of packages can be seen, which can only be seen by queries.

Publish module and cancel/uninstall module

Publishing module: npm publish
Cancellation module: npm unpublish
Abandoned module: npm deprecate [@]
Cancel the obsolete module: npm deprecate [@]', cancel the obsolete operation, is to specify an empty string (") for the message parameter.

Cancellation of a published package may not be as easy as you imagine. This operation is subject to many restrictions. Cancellation of a published package is considered a bad behavior.
1 According to the specification, unpublish is only allowed with versions published in the last 24 hours.
Even if you revoke the published package, you can no longer send the package with the same name and version as the revoked package.
Recommended alternative commands for npm unpublish: npm deprecate [@]
Using this command, you won't undo your existing package in the community, but you'll be warned when anyone tries to install it.

Updated version

For example, a 1.0.0 package has been released in npm
1. Local Update Version Number
For example, I would like to have a version 1.0.1. Note that the last modification is to add 1, then the command: npm version patch return is OK;
For example, I would like to have version 1.1.0, note that the second modification is to add 1, then the command: npm version minor return;
For example, I would like to have version 2.0.0. Note that it is the first modification to add 1, then the command: npm version major return;
2. Modify the remote version and submit it it to the remote npm:
npm publish

upgrade

Since sinopia has been discontinued, we are now replacing sinopia with verdaccio maintained by another person, which is based on sinopia and has similar functions.
Installation is similar to sinopia, see github-verdaccio address

Keywords: npm Database MySQL github

Added by Earnan on Sun, 12 May 2019 09:00:50 +0300