preface

Based on the previous understanding or internal requirements of the company, it may be that setting up CNPM warehouse has become a knowledge point that you must know. Follow me to the server to deploy a private CNPM repository.

Environmental requirements

  • System requirements: MAC or Linux (servers are mostly Linux)
  • Nodejs: version 4.2.3 or later

Basic installation

  • nodejs

    curl -sL https://rpm.nodesource.com/setup_7.x | bash - (script) yum install - y nodejs yum install - y GCC - make c + +Copy the code
  • Mysql installation

  1. Detect and uninstall existing

      rpm -qa | grep mariadb
      rpm -e --nodeps mariadb/mysql
    Copy the code
  2. Repo: MariaDB. Repo: mariadb. repo: mariadb. repo: mariadb. repo: mariadb. repo: mariadb. repo: MariaDB.

     # MariaDB 5.5 CentOS repository list - created 2014-03-04 11:20 UTC  
    # http://mariadb.org/mariadb/repositories/  
    [mariadb]  
    name = MariaDB  
    baseurl = http://yum.mariadb.org/5.5/centos6-amd64  
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB  
    gpgcheck=1 
    Copy the code

    2.2 Installing corresponding packages

      sudo yum -y install mariadb-server MariaDB-client
    Copy the code

    2.3 Starting the Service

    // If you are a centos systemctl start mariadb. Service // if you are a GUN/ Linux, only service service service mysql start // Default is empty mysqladmin -u root password"passwd"
    Copy the code

    2.4 Expansion of related commands

    //centos systemctl start mariadb# start service
    systemctl enable mariadb Set boot up
    systemctl restart mariadb # restart
    systemctl stop mariadb.service # stop MariaDB
    // gun
    service xxxx start/stop/enable/restart
    Copy the code
  • Install Git and check out the CNPMJS project

    // install git gitclone git://github.com/fengmk2/cnpmjs.org.git $HOME/cnpmjs.org
     cdMysql -u root -p create database CNPMJS; Mysql -u root -p create database CNPMJS; use cnpmjs;sourceGrant all PRIVILEGES on *.* to root@ grant all PRIVILEGES on *.* to root@The '%' identified by 'password'; // Modify the index configuration file vim config/index.js according to your needsCopy the code

Use the information

  • CNPM provides two ports: 7001 and 7002, of which 7001 is used for registration service of NPM and 7002 is used for Web access.

  • BindingHost is the IP address of the server where the CNPM is installed. That is, in the browser, you can only access the CNPM and obtain the registration service of the NPM by visiting http://192.168.0.234. RegistryHost:r.cnpmjs.org: 192.168.0.129:7001

  • Install dependencies

    // persist NPM configsetRegistry/https://registry.npm.taobao.org/configuration can be through the following ways to verify the success of NPM config get registry / / or NPM info express // Go to./cnpmjs.org and run NPM install NPM installCopy the code
  • Start the service node dispatch.js or “nohup node dispatch.js &” to start. Nohup is started in the background.

    NPM run dev: debug mode starts; npm runtest: Run test; NPM run start: starts CNPM. Permanent hot start NPM run Status: Displays the startup status of the CNPM. NPM run stop: Stops the CNPM.Copy the code
  • /lib64/libc.so.6: Versionglibc_2.14 ‘not found. This is because the version of glibc is too early. You can run the following command to view the supported version: Strings/lib64 / libc. So. 6 | grep GLIBC `, solution from the official website to download the relevant package and then compile the installation, configuration again to the relevant directory.

  1. Find a website: http://www.gnu.org/software/libc/, download version 2.14 suffix for gz compressed package, we in the root/software after download
  2. The rest is command-line operations
    [root@jrgc130 ~]#tar ZXF glibc-2.14.tar.gz
    [root@jrgc130 ~]# cd /opt/software
    [root@jrgc130 software]# tar xf glibc-2.14.tar.gz
    [root@jrgc130 software]# cd glibc-2.14
    [root@jrgc130 glibc-2.14] #mkdir build
    [root@jrgc130 glibc-2.14] #cdBuild // Modify configuration file [root@jrgc130 build]#.. /configure --prefix=/usr/local/glibc-2.14[root@jrgc130 build]# make-j4 [root@jrgc130 build]# make install // copy link library [root@jrgc130 build]#cd /usr/local/glibc-2.14/lib
    [root@jrgc130 lib]# cp libc-2.16.so /lib64/ // create link [root@jrgc130 lib]#cd /lib64
    [root@jrgc130 lib64]# rm -rf libc.so.6// Copy related files to so [root@example lib64]# /sbin/ SLN libc-2.14.so /lib64/libc.so.6// Run strings /lib64/libc.so.6| grep GLIBC can view the latest version for support2.14Problem solved.Copy the code
  • Test whether the startup is successful

    Enter http://192.168.0.234:7002/ in the browser, if appear: release private package NPM configsetRegistry https://registry.npm.taobao.org install curl CNPM client-sL https://rpm.nodesource.com/setup_7.x | bash - (script) yum install - y nodejs sudo NPM install CNPM - g change the default registry, Point to the private Registry CNPMsetRegistry http://192.168.0.234:7001Copy the code
  • Use NPM account to log in to your private registry. The account here is www.npmjs.com. If not, please register (admin login).

    $ cnpm login
    Username: admin
    Password: [email protected]
    Email: (this IS public) [email protected]
    Copy the code
  • If you cannot synchronize or download your own module during the process, you can modify the /config/index.js file

    enableAbbreviatedMetadata: true

Create private test packages

  • Generate test packages

    $ cd /tmp
    $ mkdir helloworld && cdHelloworld $CNPM init name: @cjt/ helloWorld version: 1.0.0Copy the code
  • Generate package.json (output file) :

    {
      "name": "@cjt/helloworld"."version": "1.0.0"."description": "my first scoped package"."main": "index.js"."scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": ""."license": "ISC"
    }
    Copy the code
  • Matters needing attention

  1. Note that the package name helloWorld must be prefixed with the company name @cjt, which is configured in the scopes in config/index.js

      // registry scopes, if don't set, means do not support scopes, you can set it to KKL scopes: ['@cjt', '@cnpm', '@cnpmtest', '@cnpm-test'].Copy the code
  2. The rest of the administrator account permissions distribution must be secondary development, modify the middleware/publishable js, also can be directly modified index. In the js file, the default administrator is admin;

  3. To register and log in:

  4. Publish and synchronize (see CNPM Getting Started)

    Release CNPM publish via a browser visit: http://192.168.0.129:7002/ to view and operate private CNPM server Download from the default source synchronous gulp CNPM sync gulp CNPM install gulpCopy the code

Configuration file (config/index.js)

 'use strict';

 var mkdirp = require('mkdirp');
 var copy = require('copy-to');
 var path = require('path');
 var fs = require('fs');
 var os = require('os');

 var version = require('.. /package.json').version;

 var root = path.dirname(__dirname);
 var dataDir = path.join(process.env.HOME || root, '.cnpmjs.org'); Var config = {version: version, dataDir: dataDir, /** * Cluster mode Specifies whether to enable the cluster-worker mode to start services. Default valuefalse, the production process is recommended astrue; Utilize multi-core */enableCluster: true, numCPUs: os.cpus().length, /* * server Configure the basic configuration, IP address, and request and access ports of the server (mandatory) */ registryPort: 7001, webPort: 7002, bindingHost:'10.0.0.141', // only binding on 127.0.0.1 for local access

   // debug mode
   // if in debug mode, some middleware like limit wont load
   // logger module will print to stdout
   debug: process.env.NODE_ENV === 'development',
   // page mode, enable on development env
   pagemock: process.env.NODE_ENV === 'development',
   // session secret
   sessionSecret: 'cnpmjs.org test session secret',
   // max request json body size
   jsonLimit: '10mb', / /log dir name
   logdir: path.join(dataDir, 'logs'),
   // update file template dir
   uploadDir: path.join(dataDir, 'downloads'),
   // web page viewCache
   viewCache: false,

   // config for koa-limit middleware
   // for limit download rates
   limit: {
     enable: false,
     token: 'koa-limit:download'.limit: 1000,
     interval: 1000 * 60 * 60 * 24,
     whiteList: [],
     blackList: [],
     message: 'request frequency limited, any question, please contact [email protected]',},enableCompress: false, / /enableGzip Response or not // default system admins, (the administrator must set it as his/her own clear, only the administrator can delete the module, configuration needs to restart) Admins: {// name: email fengmk2:'[email protected]',
     admin: '[email protected]',
     dead_horse: '[email protected]',
   },

   // email notification for errors
   // check https://github.com/andris9/Nodemailer for more informations
   mail: {
     enable: false,
     appname: 'cnpmjs.org',
     from: 'cnpmjs.org mail sender <[email protected]>',
     service: 'gmail',
     auth: {
       user: '[email protected]',
       pass: 'your password'
     }
   },

   logoURL: 'https://os.alipayobjects.com/rmsportal/oygxuIUkkrRccUz.jpg', // cnpm logo image url
   adBanner: ' ',
   customReadmeFile: ' ', // you can use your custom readme file instead the cnpm one
   customFooter: ' ', // you can add copyright and site total script html here
   npmClientName: 'cnpm', // use `${name}The install package `, (the default installation command symbol) packagePageContributorSearch:true, // package page contributor link to search, default is true

   // max handle number of package.json `dependencies` property
   maxDependencies: 200,
   // backup filepath prefix
   backupFilePrefix: '/cnpm/backup/'/** * database config */ database: {db:'cnpmjs',
     username: 'root',
     password: 'kkl123456',

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

     // 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 forMysql and postgresQL (since v1.5.0) pool: {maxConnections: 10, minConnections: 0, maxIdleTime: 30000 }, // the storage enginefor 'sqlite'
     // default store into ~/.cnpmjs.org/data.sqlite
     storage: path.join(dataDir, 'data.sqlite'), logging: !! process.env.SQL_DEBUG, }, // package tarball storein localFilesystem by default filesystem by default NFS: require('fs-cnpm')({
     dir: path.join(dataDir, 'nfs')
   }),
   // if set true, will 302 redirect to `nfs.url(dist.key)`
   downloadRedirectToNFS: false, // registry url name (module download request address, must be set)'10.0.0.141:7001',

   /**
    * registry mode config
    */

   // enablePrivate mode or NOT (Must be set,false// Private mode: only Admins can publish, other users just can sync package fromsource npm
   // public mode: all users can publish
   enablePrivate: false,

   // registry scopes, if don't set, means do not support scopes: ['@kkl']. // some registry already have some private packages in global scope // but we want to treat them as scoped private packages, // so you can use this white list. privatePackages: [], /** * sync configs */ CNPM WONT directly sync from this one // but sometimes will request it for some package infomations // please  don't change it if not necessary
   officialNpmRegistry: 'http://registry.npm.taobao.org',
   officialNpmReplicate: 'https://replicate.npmjs.com',

   // sync source"// If you want to directly sync from official NPM's registry // please drop them an email first sourceNpmRegistry: 'http://registry.npm.taobao.org', // upstream registry is base on cnpm/cnpmjs.org or not // if your upstream is official npm registry, please turn it off sourceNpmRegistryIsCNpm: True, // if install return 404, try to sync from source Registry. True, // sync mode select (sync mode) // none: do not sync any module, proxy all public modules from sourceNpmRegistry // exist: only sync exist modules // all: sync all modules syncModel: 'exist', / / 'none', 'all', 'exist'syncConcurrency: 1, // Sync interval, default is 10 minutes10m', // sync polular modules, default to false // because CNPM can't auto sync tag change for now
   // so we want to sync popular modules to ensure their tags
   syncPopular: false,
   syncPopularInterval: '1h',
   // top 100
   topPopular: 100,

   // sync devDependencies or not, default is false
   syncDevDependencies: false,

   // changes streaming sync
   syncChangesStream: false,
   handleSyncRegistry: 'http://127.0.0.1:7001',

   // badge subject on http://shields.io/
   badgePrefixURL: 'https://img.shields.io/badge',
   badgeSubject: 'cnpm',

   // custom user service, @see https://github.com/cnpm/cnpmjs.org/wiki/Use-Your-Own-User-Authorization
   // when you not intend to ingegrate with your company's user system, then use null, it would // use the default cnpm user system userService: null, // always-auth https://docs.npmjs.com/misc/config#always-auth // Force npm to always require authentication when accessing the registry, even for GET requests. alwaysAuth: false, // if you're behind firewall, need to request through http proxy, please set this
   // e.g.: `httpProxy: 'http://proxy.mycompany.com:8080'`
   httpProxy: null,

   // snyk.io root url
   snykUrl: 'https://snyk.io', / / https://github.com/cnpm/cnpmjs.org/issues/1149 () must be set for a patch file repair, / /if enable this option, must create module_abbreviated and package_readme table in database
   enableAbbreviatedMetadata: true,

   // global hook function: function* (envelope) {}
   // envelope format please see https://github.com/npm/registry/blob/master/docs/hooks/hooks-payload.md#payload
   globalHook: null,
 };

 if (process.env.NODE_ENV === 'test') {
   config.enableAbbreviatedMetadata = true;
 }

 if(process.env.NODE_ENV ! = ='test') {
   var customConfig;
   if (process.env.NODE_ENV === 'development') {
     customConfig = path.join(root, 'config'.'config.js');
   } else {
     // 1. try to load `$dataDir/config.json` first, not exists then goto 2.
     // 2. load config/config.js, everything in config.js will cover the same key in index.js
     customConfig = path.join(dataDir, 'config.json');
     if(! fs.existsSync(customConfig)) { customConfig = path.join(root,'config'.'config.js'); }}if (fs.existsSync(customConfig)) {
     copy(require(customConfig)).override(config);
   }
 }

 mkdirp.sync(config.logdir);
 mkdirp.sync(config.uploadDir);

 module.exports = config;

 config.loadConfig = function (customConfig) {
   if(! customConfig) {return;
   }
   copy(customConfig).override(config);
 };
Copy the code

Refer to test documentation

  • CNPM configuration
  • CNPM official website document introduction