目标是为私人NPM提供一个低成本的维护和易于使用的解决方案。
利用cnpmjs.org你可以:
1、搭建一个企业的npm私有库
2、搭建一个npm的镜像
3、搭建一个完全独立于npm的仓库来存放你想存放的东西
一:安装nodejs和mysql
二:安装cnpm
1.从github上下载源码
git clone git://github.com/fengmk2/cnpmjs.org.git cd cnpm.org
2.初始化数据
在docs/db.sql 和生成的表
3.新建config.js 配置文件 特别注意sourceNpmRegistry和registryHost (自己本地的ip),其他人访问时请求的地址
module.exports = {
debug: true,
enableCluster: true, // enable cluster mode
enablePrivate: false, // enable private mode, only admin can publish, other use just can sync package from source npm
database: {
db: 'cnpmjs',
host: 'localhost',
port: 3306, //unknown database cnpmjs
username: 'root',
password: 'wqt5179495',
dialect:'mysql',
},
admins: {
admin: 'admin@cnpmjs.org',
},
syncModel: 'exist',// 'none', 'all', 'exist',
sourceNpmRegistry:"http://172.25.31.5/",
registryHost: '172.25.31.5:7001',
};
这里需要注意的一点就是,在index.js里面有个叫做bindingHost的配置,这个意思是本地访问时的绑定地址,默认配置是127.0.0.1。也就是说本地你只能通过这个地址访问,如果使用localhost的话是访问不了的,用其他IP也不行
4.启动和停止服务
npm start npm stop
cnpmjs有默认的两个访问端口:
1) 7001是registry端口,对应registryPort配置项
2) 7002是web端口,对应webPort配置项
启动成功:
5.设置源:
npm config set registry:http://192.168.1.6:7001
也可以在每个命令后面加--registry
6.发布包
npm publish --registry=http://127.0.0.1:7001
6.下载
npm install weiqingtao --registry=http://127.0.0.1:7001(其他人下载的话,后面换成ip)