依賴安裝
- npm i -g cnpmjs.org
修改node_modules/cnpmjs.org/config/index.js 文件
把下面的copy一下,替換到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
*/
enableCluster: false,
numCPUs: os.cpus().length,
/*
* server configure
*/
registryPort: 7001, //倉庫訪問端口(執行發佈安裝)
webPort: 7002, //展示查詢站點訪問端口
bindingHost: '', //監聽綁定的 Host,默認127.0.0.1,外網訪問註釋掉此項即可
// 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, // enable gzip response or not
// default system admins 默認管理員賬號
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} install package`
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 //數據庫相關設置 默認sqlite, 使用mysql
*/
database: {
db: 'cnpmjs', //數據庫名稱
username: 'root', //賬號
password: '123456', // 密碼
// the sql dialect of the database
// - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb'
dialect: 'mysql', //,默認sqlite,這裏我們改成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,
},
// package tarball store in local filesystem by default
// node包 下載位置, 本地存儲
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
//模塊註冊列表訪問域名,默認r.cnpmjs.org,安裝模塊時會到這個域名下查找,這個默認設置略坑,建議沒有外網域名的先清空回頭再配
registryHost: '',
/**
* registry mode config 私有模塊發佈相關配置
*/
//是否開啓私有模式,默認爲 false;
//私有模式下只有管理員能發佈模塊,其他賬號只有同步權限
//非私有模式,註冊用戶都可以發佈模塊
enablePrivate: false,
// registry scopes, if don't set, means do not support scopes
//若爲非私有模式發佈則此項必填,非管理員發佈模塊式命名必須以scopes字段開頭,模塊命名示例“@cnpm/packagename”
scopes: [ '@cnpm', '@cnpmtest', '@cnpm-test' ],
// 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.
// 私有模塊非scopes白名單,各種非以scope方式發佈的老模塊的白名單管理,數組形式維護
privatePackages: [],
/**
* sync configs 同步源倉庫相關設置
*/
//npm官方registry地址,不會直接從這個地址同步模塊,但有時會從這裏獲取模塊信息,除非必要請勿更改
// the official npm registry
// 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: 'https://registry.npmjs.com',
officialNpmReplicate: 'https://replicate.npmjs.com',
// sync source, upstream registry
// If you want to directly sync from official npm's registry
// please drop them an email first
//同步模塊上游registry地址
sourceNpmRegistry: 'https://registry.npm.taobao.org',
//上游registry是否是cnpm,默認true,若要使用npm官方地址作爲同步上游,請設置爲false
sourceNpmRegistryIsCNpm: true,
//若安裝時模塊不存在,是否向源registry進行同步,默認true
syncByInstall: true,
// 同步模式選項
// none: 不進行同步,只管理用戶上傳的私有模塊,公共模塊直接從上游獲取
// exist: 只同步已經存在於數據庫的模塊
// all: 定時同步所有源registry的模塊
syncModel: 'exist', // 'none', 'all', 'exist'
syncConcurrency: 1,
// 同步時間間隔,默認10分鐘
syncInterval: '10m',
// 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,
// 是否同步模塊中devDependencies,默認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,
// 一定要加上這個爲true, 默認爲false
enableAbbreviatedMetadata: true,
// 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',
};
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);
};
- 安裝mysql
命令行 或者 使用Navicat for MySQL
登錄
mysql -uroot -p
create database cnpmjs;
show databases;
use cnpmjs;
導數據
source c://xxx/xxx/docs/db/sql
show tables;
- nrm
npm i -g nrm
nrm add knpm http://127.0.0.1:7001
nrm use knpm
- pm2
npm i -g pm2
pm2 ls
pm2 start file
pm2 stop id
pm2 delete id
pm2 start dispatch.js
cnpmjs.org start
選擇某個包sync
總結
- 相對於 verdaccio, 會下載相關的包, 及其版本, 可以自動更新包, 但是相對而言本地文件也會相應增加